The two steps of building boost_1.47( boost 配置安装在WIN和LINUX)

//********************************************
the steps of building boost_1.47 are two:

1st step: >bootstrap.bat
2nd step: > bjam.exe.
.............as follows,
//********************************************

 
method A: (build and install the "header" and the "new-builded library" files)

C:\3rd_Library\boost_147\boost_1_47_0>
C:\3rd_Library\boost_147\boost_1_47_0>
C:\3rd_Library\boost_147\boost_1_47_0>bjam --build-dir="c:\3rd_Library\boost_147\build_dir" toolset=msvc-9.0 --with-thread threading=multi --prefix="c:\3rd_Library\Boost" --build-type=complete install

 


method B:(only build the "new-builded library" files)

C:\3rd_Library\boost_147\boost_1_47_0>
C:\3rd_Library\boost_147\boost_1_47_0>
C:\3rd_Library\boost_147\boost_1_47_0>bjam --build-dir="c:\3rd_Library\boost_147\build_dir" toolset=msvc-9.0 --with-thread threading=multi --build-type=complete stage

 

rem: without the item:  --prefix="c:\3rd_Library\Boost" , because of the item will be invalid under "stage"!!!!

 


//*******************************
other usage:
1)only build "debug" version ,adding "variant=debug", because of system default is "debug" and "release"

C:\3rd_Library\boost_147\boost_1_47_0>
C:\3rd_Library\boost_147\boost_1_47_0>
C:\3rd_Library\boost_147\boost_1_47_0>bjam --build-dir="c:\3rd_Library\boost_147\build_dir" toolset=msvc-9.0 --with-thread threading=multi variant=debug --build-type=complete stage

 


//*************************************
To make Boost build system produce 64 bit libraries instead of 32 bit ones, change the address-model option to 64.


prompt> bjam --toolset=msvc-9.0 link=static address-model=64 --with-thread --with-system --with-filesystem --with-date_time --build-type=complete stage

 

下面一个blog 的总结也挺好,http://eksay.blogcn.com/articles/boost-%E9%85%8D%E7%BD%AE%E5%AE%89%E8%A3%85%E5%9C%A8win%E5%92%8Clinux.html

boost 配置安装在WIN和LINUX

1.解压缩到d:\boost目录下

2. 命令提示到: cd  /d  d:\boost\boost_1_48_0\

3. 运行bootstrap.bat生成bjam.exe (boost自己的make)

4. 设定编译环境 (可选,如果想去掉编译警告需要修改)
修改user-config.jam (D:/boost/boost_1_48_0/tools/build/v2/user-config.jam) 的MSVC configuration

# MSVC configuration

# Configure msvc (default version, searched for in standard locations and PATH).
# using msvc ;

using msvc : 10.0 : : <compileflags>/wd4819 <compileflags>/D_CRT_SECURE_NO_DEPRECATE <compileflags>/D_SCL_SECURE_NO_DEPRECATE <compileflags>/D_SECURE_SCL=0 ;

5.编译与安装:

(1) 编译boost库
bjam   --toolset=msvc-10.0  --build-type=complete --prefix="d:\boost\boost_1_48_0" stage

运行完后(弹出输入提示符)
(2) 则安装,输入:
bjam   --toolset=msvc-10.0  --build-type=complete --prefix="d:\boost\boost_1_48_0" install

6. 设定vs2010环境。( 注:在2010环境下这步,在项目-->右键属性-->VC++ Directories 中去填写对应路径 )

修改环境变量:$(BOOST):  D:/boost/boost_1_48_0
Tools -> Options -> Projects and Solutions -> VC++ Directories
在Library files加上$(BOOST)/bin/vc10/lib, 在Include files加上$(BOOST)

当然以上配置只对当前工程有效。下面介绍一下“一次性配置”的方法,也就是配置一次,以后就不用每次配置了。

.执行菜单栏“视图——其他窗口——属性管理器”,可以看到“属性管理器”显示在工作区左侧,双击Debug | Win32下的“Microsoft.Cpp.Win32.user“,在弹出的配置框中配置。这个设置是对所有工程有效的

7.使用举例:

#include<boost/thread.hpp>

此时,不用包含库文件,boost的auto-link机制将会自动帮我们包含对应的静态lib。也就是说,boost默认是以静态方式链接的,这样我们的工程属性最好也设为Multi-threaded (Debug)。如果想使用dll动态方式链接,需要预先定义宏:

#define BOOST_ALL_DYN_LINK

同样,此时boost也会默认帮我们包含对应的lib。如果不想使用boost提供的auto-link机制,或者对它的自动链接不太放心的话(其实大可不必担心),可以预先定义宏:

#define BOOST_ALL_NO_LIB

然后使用以下方法链接:

#pragma comment(lib, "boost_thread-vc100-mt-1_46.lib")或

#pragma comment(lib, "boost_thread-vc100-mt.lib")

这两个lib其实是一样的,实在不明白boost编译时为什么每个库都要复制一份,难道是因为后者在升级boost版本后不用改代码?另外还有一个比较有用的宏:

#define BOOST_LIB_DIAGNOSTIC

它可以让VC在编译时的output窗口中输出程序具体链接了哪些boost库以及链接顺序。

关于boost的auto-link机制,详细可以看看boost/config/auto_link.hpp里的代码,很容易可以读懂,并且值得我们学习。

用下面的程序测试下环境配置

#include <fstream>

// include headers that implement a archive in simple text format
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/lexical_cast.hpp>

/////////////////////////////////////////////////////////////
// gps coordinate
//
// illustrates serialization for a simple type
//
class gps_position
{
private:
friend class boost::serialization::access;
// When the class Archive corresponds to an output archive, the
// & operator is defined similar to <<.  Likewise, when the class Archive
// is a type of input archive the & operator is defined similar to >>.
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & degrees;
ar & minutes;
ar & seconds;
}
int degrees;
int minutes;
float seconds;
public:
gps_position(){};
gps_position(int d, int m, float s) :
degrees(d), minutes(m), seconds(s)
{}

std::string toString()
{
return  "degrees: " + boost::lexical_cast<std::string>(degrees) +
"minutes:  " + boost::lexical_cast<std::string>(minutes) +
"seconds: " + boost::lexical_cast<std::string>(seconds);
}
};

int main() {
// create and open a character archive for output
std: fstream ofs("filename");

// create class instance
const gps_position g(35, 59, 24.567f);

// save data to archive
{
boost::archive::text_oarchive oa(ofs);
// write class instance to archive
oa << g;
// archive and stream closed when destructors are called
}

// ... some time later restore the class instance to its orginal state
gps_position newg;
{
// create and open an archive for input
std::ifstream ifs("filename");
boost::archive::text_iarchive ia(ifs);
// read class state from archive
ia >> newg;

// archive and stream closed when destructors are called
}

std::cout << newg.toString() << std::endl;
std::cin.get();
return 0;
}

结果应该是

degrees: 35minutes:  59seconds: 24.5669994

 

 

你可能感兴趣的:(linux,serialization,Class,Build,library,archive)