Windows&Linux平台编译配置boost1.45

来源:互联网 发布:石油化工基础数据手册 编辑:程序博客网 时间:2024/05/17 15:05

1、下载解压

一般下载tar tar.bz2 tar.gz zip相对linux解压比较方便,而win则是zip rar tar tar.gz tar.bz2。

linux默认没有rar命令,没有7z命令,win默认没有7z命令,winrar一般装机都有的。

推荐tar.gz tar.bz2 tar zip都可以。

Win平台直接用winrar打开解压即可。

Linux平台tar.gz包使用tar -zxvf,tar tar.bz2使用tar -xvf,zip包使用unzip -d 目录 xxx.zip

 

网络带宽小可以考虑下载7z的源码包,因为他压缩率高,下载时间短。7z包:boost_1_45_0.7z

Win平台需要安装7z,装完winrar也会支持7z包

Linux平台需要安装7z命令行版本,解压命令:

#7z x boost_1_45_0.7z

x 表示以原文件名为解压路径

使用7z x boost_1_45_0.7z > /dev/null丢弃显示信息,这样更快些,缺点是出错看不到信息。

 

2、先编译bjam(Win平台确保是管理员账户,Linux平台确保是root账户)

Win平台运行bootstrap.bat

Linux平台运行bootstrap.sh,如无权限先

# chmod 755 ./bootstrap.sh

# chmod 755 ./libs/gil/doc/build.sh
# chmod 755 ./tools/build/v2/engine/src/build.sh
# ./bootstrap.sh

 

3、编译boost

WIN平台

bjam --toolset=gcc --build-type=complete "--prefix=c:/boost_gcc4.5.0" install

表示编译所有库:编译出344个lib,44个dll。

其中lib(静态库)包括单线程release、多线程release、单线程debug、多线程debug四种版本。

其中dll(动态库)只包括多线程release、和多线程debug两种,可能因为单线程版动态库实际应用极少。

默认是安装的VC编译器,使用--toolset=msvc-9.0(gcc)来制定编译器

默认编译到c:/boost,包括include和lib

Linux平台

貌似不支持./bjam --build-type=complete,我们用:

./bjam release install 编译release库并安装

./bjam debug install 编译debug库并安装
头文件默认是/usr/local/include

库文件默认是/usr/local/lib

./bjam -sTOOLS=gcc --includedir=目录 --libdir=目录 install

4、

Win平台在IDE的配置中加入头文件和库文件路径

Linux平台

vi ~/.bash_profile

最后加入

export boost='
-lboost_date_time
-lboost_filesystem
-lboost_graph
-lboost_iostreams
-lboost_math_c99
-lboost_math_c99f
-lboost_math_c99l
-lboost_math_tr1
-lboost_math_tr1f
-lboost_math_tr1l
-lboost_prg_exec_monitor
-lboost_program_options
-lboost_python
-lboost_regex
-lboost_serialization
-lboost_signals
-lboost_system
-lboost_unit_test_framework
-lboost_wave
-lboost_wserialization'
以后编译就可以使用g++ xxx.cpp $boost即可。

原创粉丝点击