1. 下载并解压Boost C++ Libshtml
下载地址:python
SourceForge:http://sourceforge.net/projects/boost/files/boost/1.48.0/linux
Boost Official:http://www.boost.org/users/history/version_1_48_0.html (实际上也是从SourceForge下载)ios
解压到 E:\boost_1_48_0c++
发现上面的版本编译不出64位,只有32位,哪怕指定了--address-model=64git
能够去https://www.boost.org/users/history/ 这边下一个boost_1_48_0,在试试看bootstrap
推荐使用boost_1_66_0 可以生成64位和32位的windows
2. 编译多线程
咱们须要对全部 编译器版本(Visual Studio 20** Command Prompt对应的编译器版本(区分32和64位)+toolset的指定)+32/64版本+debug/release版本 各执行一次编译函数
打开VS2008,在菜单栏“工具”选择“Visual Studio 2008 Command Prompt”,在弹出的控制台中,输入:
C:\Users\Michael>E: E:\>cd boot_1_48_0 E:\>bootstrap.bat E:\>b2 stage --build-type=complete --toolset=msvc-9.0 --address-model=32 --variant=debug --threading=multi --link=static --runtime-link=shared --build-dir=".\bin.v2.vc2008_x86_d" --stagedir=".\"
E:\>b2 stage --build-type=complete --toolset=msvc-9.0 --address-model=32 --variant=release --threading=multi --link=static --runtime-link=shared --build-dir=".\bin.v2.vc2008_x86_r" --stagedir=".\"
在菜单栏“工具”选择“Visual Studio 2008 x64 Win64 Command Prompt”,在弹出的控制台中,输入:
C:\Users\Michael>E:
E:\>cd boot_1_48_0 E:\>bootstrap.bat E:\>b2 stage --build-type=complete --toolset=msvc-9.0 --address-model=64 --variant=debug --threading=multi --link=static --runtime-link=shared --build-dir=".\bin.v2.vc2008_x64_d" --stagedir=".\"
E:\>b2 stage --build-type=complete --toolset=msvc-9.0 --address-model=64 --variant=release --threading=multi --link=static --runtime-link=shared --build-dir=".\bin.v2.vc2008_x64_r" --stagedir=".\"
每一条b2大概执行一个小时。且每一条b2,虽然32位、64位、debug、release不一样的组合编译设置,但编译出来的东西是同样的,为何?
由于--build-type=complete,在boost_1_66_0中,决定了能够编译全部的--threading、--runtime-link、--variant、--address-model、--link;在boost_1_48_0中,决定了能够编译全部的--variant、--link,但--threading=multi、--runtime-link=shared、--address-model=32(能够经过查看编译出来的dll是否为32位仍是64位)。可是--toolset默认使用系统安装的最高版本的VC,跟用例如Visual Studio的Visual Studio 2008 x64 Win64 Command Prompt命令提示符不要紧。
中间文件都在bin.v2*目录下
bootstrap.bat用来完成编译前的配置工做。如生成bjam.exe和b2.exe bjam.exe 是老版本,b2是bjam的升级版本,都是可行的
其中“--toolset=msvc-9.0”表示编译成VS 9.0版本,由于VS 2008为VS 9.0版本,若是是VS 2010,则用“--toolset=msvc-10.0”参数。
(1)b2 stage --build-type=complete --toolset=msvc-10.0 或者(2)bjam.exe stage --build-type=complete --toolset=msvc-10.0。,推荐使用(1)
complete是个生成全部当前系统上有的编译器的调试版和发行版的静态库和动态库的过程。最后大小在windows上是5G样子。
若是:
目标位置如./stage/lib下有存在的结果文件了,则直接跳过编译和跳过拷贝操做。
目标位置如./stage/lib下没有存在的结果文件,则直接跳过编译,但执行从./bin.v2文件夹下拷贝相应的文件操做。
./bin.v2文件夹不存在,则会执行编译。因此在每次编译的时候,最好要把这个文件夹删除,且把./stage/lib这个已经存在的文件夹更名。
编译是很漫长的过程,若是你只须要使用Boost库的一部分,能够选择性地编译。好比你只想用system,thread库,则输入:
E:\>bjam --toolset=msvc-9.0 --with-system -with-thread
下面详细解释一下每一个参数的含义:
stage/install:stage 表示只生成库(dll和lib),install还会生成包含头文件的include目录。本人推荐使用stage,由于install生成的这个include 目录实际就是boost安装包解压缩后的boost目录(E:\SDK\boost_1_39_0\boost,只比include目录多几个非hpp文件,都很小),因此能够直接使用,并且不一样的IDE均可以使用同一套头文件,这样既节省编译时间,也节省硬盘空间。
toolset:指定编译器,可选的如borland、gcc、msvc(VC6)、msvc-7.1(vs2003)、msvc-8.0(vs2005)、msvc-9.0(vs2008)、msvc-10.0(VS20010)、msvc-12.0(VS20013)等。若是不指定,则生成某一个系统默认的编译器版本。跟从Visual Studio 20** Command Prompt对应的编译器版本不要紧。
--without-/--with-:选择不编译/编译哪些库。由于python、mpi等库我都用不着,因此排除之。另外,wave、graph、math、regex、test、 program_options、serialization、signals这几个库编出的静态lib都很是大,因此不须要的也能够without掉。这能够根据各人须要选择,默认是所有编译。
--stagedir/--prefix:stage 时使用stagedir,install时使用prefix(--prefix跟--stagedir连用时,只有--prefix起做用),表示编译生成文件的路径。推荐给不一样的IDE指定不一样的目录,如VS2010对应的是 E:\SDK\boost_1_46_1\vc10,VC6对应的是E:\SDK\boost_1_45_0\vc6,不然都生成到一个目录下面,难以管理。若是使用了install参数,那么还将生成头文件目录,vc9若是--prefix=E:\SDK\boost_1_46_1\vc9 对应的就是E:\SDK\boost_1_46_1\vc9 \include\boost-1_66\ (其下有boost目录),vc6相似(光这路径都这样累赘,仍是使用stage好)。
--stagedir=".\bin\vc12_x86" --stagedir=".\bin\vc12_x64" 默认是./stage
--build-dir:编译生成的中间文件的路径。这个本人这里没用到,默认就在根目录(E:\SDK\boost_1_46_1)下,目录名为bin.v2,等编译完成后可将这个目录所有删除(没用了),因此不须要去设置。
--build-type:
默认是minimal, on Windows, these are static multithreaded libraries in debug and release modes, using shared runtime; on Linux, these are static and shared multithreaded libraries in release mode.
Complete, build all possible variations.(就是说build全部支持的编译选项)
--variant:决定编译什么版本。variant=debug variant=release
debug/release:?编译debug/release版本。通常都是程序的debug版本对应库的debug版本,因此两个都编译。若是不指定,则两种方式都生成;也能够所有指定如: debug release 注意:linux上只能同时使用一种且不带--variant=
link:生成动态连接库/静态连接库。生成动态连接库需使用shared方式,生成静态连接库需使用static方式。通常boost库可能都是以static方式编译,由于最终发布程序带着boost的dll感受会比较累赘。若是不指定,则两种方式都生成。
runtime-link:动态/静态连接C/C++运行时库。一样有shared和static两种方式。若是不指定,则两种方式都生成。通常都是使用shared
这样runtime-link和link一共能够产生4种组合方式,各人能够根据本身的须要选择编译。通常link只选static的话,只须要编译2种组合便可,即link=static runtime-link=shared(推荐)和link=static runtime-link=static。
threading:单/多线程编译。通常都写多线程程序,固然要指定threading=multi方式了(默认);若是须要编写单线程程序,那么还须要编译单线程库,可使用single方式。
--address-model:默认生成32位的平台库,加入address-model=64属性才能生成64位的DLL。
--architecture:architecture=x86 (32位和64位都用这个)
--help:
3. 配置VS2008环境
在菜单栏的“工具”——“选项”——“项目和解决方案”——“VC++目录”,“平台”选择“Win32”。
“显示如下内容的目录”选择“包含文件”,点击“新建”按钮,文件夹选择“E\boost_1_48_0”。
“显示如下内容的目录”选择“库文件”,点击“新建”按钮,文件夹选择“E:\boost_1_48_0\stage\lib”。
4.编写代码测试
注:若是编写的测试代码出现相似错误”没法打开包括文件:“boost/regex.hpp”: No such file or directory” 说明附件包含目录出现错误,这时要纠正包含目录。
若是在下还有incude目录,咱们只需包含includes目录就加载了相关头文件,若是没有,如上加载总目录,让编译器本身找。
附加:在第2步的时候,若是将执行指令里面的“stage”改为”install”,则会生成include指令。
1 #include<iostream> 2 #include <boost/regex.hpp> 3 using namespace std; 4 5 int main() 6 { 7 // 3 digits, a word, any character, 2 digits or "N/A", 8 // a space, then the first word again 9 boost::regex reg("\\d{3}([a-zA-Z]+).(\\d{2}|N/A)\\s\\1"); 10 11 std::string correct="123Hello N/A Hello"; 12 std::string incorrect="123Hello 12 hello"; 13 14 assert(boost::regex_match(correct,reg)==true); 15 assert(boost::regex_match(incorrect,reg)==false); 16 cout<<"Hello Boost !"<<endl; 17 }
参见:https://www.cnblogs.com/zhcncn/p/3950477.html
所获得的结果以下表所示:
序号 | link | runtime-link | 生成物 | 备注 |
1 | static | static | libboost_date_time-vc120-mt-sgd-1_56.lib libboost_date_time-vc120-mt-s-1_56.lib |
|
2 | static | shared | libboost_date_time-vc120-mt-gd-1_56.lib libboost_date_time-vc120-mt-1_56.lib |
与5结果相同 |
3 | shared | shared | boost_date_time-vc120-mt-gd-1_56.dll boost_date_time-vc120-mt-gd-1_56.lib boost_date_time-vc120-mt-1_56.dll boost_date_time-vc120-mt-1_56.lib |
|
4 | shared | static | 报错,没法编译 | |
5 | 使用缺省 | 使用缺省 | libboost_date_time-vc120-mt-gd-1_56.lib libboost_date_time-vc120-mt-1_56.lib |
与2结果相同 而且在省略debug release时,debug release版本都编译 |
6 | 使用--build-type=complete | boost_date_time-vc120-mt-gd-1_56.dll boost_date_time-vc120-mt-gd-1_56.lib boost_date_time-vc120-mt-1_56.dll boost_date_time-vc120-mt-1_56.lib
libboost_date_time-vc120-mt-sgd-1_56.lib libboost_date_time-vc120-mt-s-1_56.lib
libboost_date_time-vc120-mt-gd-1_56.lib libboost_date_time-vc120-mt-1_56.lib
libboost_date_time-vc120-s-1_56.lib libboost_date_time-vc120-sgd-1_56.lib |
--build-type=complete时,能够看到link,runtime-link的 3种组合下debug, release的多线程版本都生成出来了, 除此以外,还生成了link=static,runtime-link=static的debug, release的单线程版本 |
从上面的结果能够看到,link和runtime-link的缺省配置是 link=static runtime-link=shared,因此咱们可使用 (b2 stage --toolset=msvc-12.0 --with-date_time --stagedir="E:\eCode\boost_1_56_0\bin\vc12_2")命令行来编译boost。
另外,咱们还能够分析一下 boost 库的命名特色:【2】
(1)以“lib”开头的是“link=static”版本(静态连接库版本,没有dll),而直接以“boost”开头的是“link=shared”版本(动态连接库版本,包含lib和dll)。
(2)全部的库都含有"boost"前缀。
(3)紧随其后的是boost库名称(好比date_time库)。
(4)而后是编译器的版本,与库名称之间以"-"而不是下划线"_"分隔(好比 -vc120)。
(5)有“mt”的为“threading=multi”版本,没有的则是“threading=single”版本。
(6)有“s”的为“runtime-link=static”版本,没有的则是“runtime-link=shared”版本。
(7)有“gd”的为debug版本,没有的则是release版本。
(8)全部的库都含有boost库的版本号结尾(好比1_56,其中的"."如下划线"_"代替)
3. link, runtime-link 组合分析
文章【2】给出了link,runtime-link的具体做用分析。
假设一个库A依赖于库B,咱们本身的程序client依赖于库A,即:
那么,link指的是client->A,runtime-link指的是A -> B
配置 |
连接过程 |
运行时须要的文件 |
link=static runtime-link=static |
client经过A.a (A.lib)静态包含A; A经过B.a (B.lib)静态包含B; 不关 .so .dll的事 |
client |
link=static runtime-link=shared |
client经过A.a (A.lib)静态包含A; 在运行时,client要动态调用B.so (B.dll) |
client B.so (B.dll) |
link=shared runtime-link=shared |
client会包含A.a (A.lib); A会包含 B.a (B.lib); 但都只保存动态库的真正实现的stub,运行时经过stub去动态加载 A.so (A.dll), B.so (B.dll) 中的实现 |
client A.so (A.dll) B.so (B.dll) |
link=shared runtime-link=static |
client会包含A.a (A.lib),但只包含真正实现的stub; A经过B.a (B.lib)静态包含B; 运行时,client会动态调用A.so (A.dll) |
client A.so (A.dll)
|
包含头文件的Include路径:E:\eCode\boost_1_56_0
包含库文件的连接路径:E:\eCode\boost_1_56_0\bin\vc12\lib
(1)能够设置为仅用于当前project:
选中当前project->Properties->Configuration Properties->C/C++->General: Additional Include Directories: 设置 E:\eCode\boost_1_56_0
选中当前project->Properties->Configuration Properties->Linker->General: Additional LibraryDirectories: 设置 E:\eCode\boost_1_56_0\bin\vc12\lib
(2)可设置为仅用于当前Solution:
选中当前project->Properties->Configuration Properties->VC++ Directories:
Include Directories: 设置 E:\eCode\boost_1_56_0
LibraryDirectories: 设置 E:\eCode\boost_1_56_0\bin\vc12\lib
(3)可设置为OS当前用户下的VC++环境(当前用户下VC++所建立的全部Solution)
在某个已打开的工程下,切换到Property Manager 选项卡,而后而后展开当前工程的properties配置,打开Microsoft.Cpp.Win32.User
选择Common Properties->VC++ Directories:
Include Directories: 设置 E:\eCode\boost_1_56_0
LibraryDirectories: 设置 E:\eCode\boost_1_56_0\bin\vc12\lib
这样设置的仅在Win32编译选项下起做用,x64编译选项须要另外配置x64的properties sheet。
(4)可设置为OS全部用户下的VC++环境
能够编辑 Microsoft.Cpp.Default.props 、Microsoft.Cpp.props 。这里就不介绍了。
使用文章【3】中date_time计时函数。建立一个Win32 console 工程,而后copy下面代码
//#define BOOST_DATE_TIME_SOURCE #include <iostream> #include <boost/date_time/gregorian/gregorian.hpp> #include <boost/date_time/posix_time/posix_time.hpp> using namespace std; using namespace boost::gregorian; using namespace boost::posix_time; /************************************************************************ 建立微秒级的计时器 ************************************************************************/ template <class T = microsec_clock> class MyTimer { private: ptime m_startTime; public: MyTimer() { Restart(); } void Restart() { m_startTime = T::local_time(); } void Elapsed() { cout << T::local_time() - m_startTime << endl; } }; int main() { MyTimer<microsec_clock> t; for(int i = 0; i < 100; ++i) { cout << "hello" << endl; } t.Elapsed(); }
注意开头的宏 “#define BOOST_DATE_TIME_SOURCE” 注掉了。若启用这个宏定义,则默认由编译器从新编译嵌入的头文件;若不启用这个宏定义,则表示使用系统已编译好的date_time库。
(1)禁用#define BOOST_DATE_TIME_SOURCE 宏,而后将 libboost_date_time-vc120-mt-gd-1_56.lib 从 E:\eCode\boost_1_56_0\bin\vc12\lib 中移除,编译debug版的程序时,提示链接错误,缺乏libboost_date_time-vc120-mt-gd-1_56.lib。
(2)启用#define BOOST_DATE_TIME_SOURCE 宏,编译debug版的程序时,可发现即便在缺乏 libboost_date_time-vc120-mt-gd-1_56.lib的状况下,也能成功编译。
【1】Boost下载安装编译配置使用指南(含Windows、Linux以及ARM Linux)(http://www.cnblogs.com/wondering/archive/2009/05/21/boost_setup.html)
【2】link 和 runtime-link,搭配shared 和 static(http://blog.csdn.net/yasi_xi/article/details/8660549)
【3】计时函数(二)(http://www.cnblogs.com/jerry19880126/archive/2013/02/20/2919718.html)
【4】官方文档Getting Started on Windows(http://www.boost.org/doc/libs/1_56_0/more/getting_started/windows.html)
【5】bjam使用(http://blog.chinaunix.net/uid-22301538-id-3158997.html)
1. x64环境下编译得先从开始菜单启动Visual Studio的Visual Studio 2010 x64 Win64 Command Prompt进入命令提示符(也能用于build VS20十、VS2015的boost库。x64兼容(Visual Studio 2010 x64 cross Command Prompt)能够在32位系统上编译出在64位系统上运行的程序,而x64(Visual Studio 2010 x64 Win64 Command Prompt)本机是指在64位系统上编译出在64位系统上运行的程序。也就是说x64兼容在通常状况下使用都没有错,无论你的系统是32位仍是64位。),而不是随便打开任意一个命令行窗口就行。
2. 而后转到boost根文件夹,运行bootstrap.bat生成x64版的b2。
3. 而后运行命令:
在boost_1_66_0中
b2 stage --build-type=complete --stagedir=".\lib" --toolset=msvc-10.0 这个用于VS2010
b2 stage --build-type=complete --stagedir=".\lib" --toolset=msvc-14.0 这个用于VS2015 强烈推荐! 全部版本的库文件,都会生成在.\lib\下,都不冲突
若是编译过程当中,出现boost\move\detail\type_traits.hpp中decltype不认识的,在项目的预约义中加入BOOST_NO_CXX11_DECLTYPE (我在VS2010上的x64位上成功了) 参见:config\compiler\visualc.hpp 或 linux上参见config\compiler\gcc.hpp
在boost_1_48_0中(发现只能生成32位的)
b2 stage --build-type=complete --stagedir=".\" --toolset=msvc-10.0 --address-model=64 这个用于VS2010 强烈推荐! 全部版本的库文件,都会生成在.\lib\下,都不冲突
把bin.v2删除 没有这步,则下面这步仍是直接拷贝上一步的内容
b2 stage --build-type=complete --stagedir=".\" --toolset=msvc-10.0 --address-model=32 这个用于VS2010 强烈推荐! 全部版本的库文件,都会生成在.\lib\下,都不冲突
b2 stage --build-type=complete --stagedir=".\" --toolset=msvc-14.0 --address-model=64 这个用于VS2015
把bin.v2删除 没有这步,则下面这步仍是直接拷贝上一步的内容
b2 stage --build-type=complete --stagedir=".\" --toolset=msvc-14.0 --address-model=32 这个用于VS2015
4. 而后拷贝头文件目录D:\boost_1_66_0\boost\到目的地目录的header\下,固然也能够放在原地(即不用执行这不)
这里以 filesystem库为例,以下是它在暂存文件里的层次结构:
/debug
boost_filesystem-mgw45-d-1_40.lib
boost_filesystem-mgw45-d-1_40.dll/debug/link-static
libboost_filesystem-mgw45-d-1_40.lib/debug/link-static/runtime-link-static
libboost_filesystem-mgw45-sd-1_40.lib/debug/link-static/runtime-link-static/threading-multi
libboost_filesystem-mgw45-mt-sd-1_40.lib/debug/link-static/threading-multi
libboost_filesystem-mgw45-mt-d-1_40.lib/debug/threading-multi
boost_filesystem-mgw45-mt-d-1_40.lib
boost_filesystem-mgw45-mt-d-1_40.dll/release
boost_filesystem-mgw45-1_40.dll
boost_filesystem-mgw45-1_40.lib/release/link-static
libboost_filesystem-mgw45-1_40.lib/release/link-static/runtime-link-static
libboost_filesystem-mgw45-s-1_40.lib/release/link-static/runtime-link-static/threading-multi
libboost_filesystem-mgw45-mt-s-1_40.lib/release/link-static/threading-multi
libboost_filesystem-mgw45-mt-1_40.lib/release/threading-multi
boost_filesystem-mgw45-mt-1_40.dll
boost_filesystem-mgw45-mt-1_40.lib
由以上的文件夹层次结构基本就能够得出结论:
1、以“lib”开头的是“link-static”版本的,而直接以“boost”开头的是“link-shared”版本的。
2、有“d”的为debug版本,没有的则是release版本。
3、有“s”的为“runtime-link-static”版本(使用静态CRT),没有的则是“runtime-link-shared”版本(使用动态CRT)。
4、有“mt”的为“threading-multi”版本,没有的则是“threading-single”版本。
(1)以“lib”开头的是“link=static”版本(静态连接库版本,没有dll),而直接以“boost”开头的是“link=shared”版本(动态连接库版本,包含lib和dll)。
(2)全部的库都含有"boost"前缀。
(3)紧随其后的是boost库名称(好比date_time库)。
(4)而后是编译器的版本,与库名称之间以"-"而不是下划线"_"分隔(好比 -vc120)。
(5)有“mt”的为“threading=multi”版本,没有的则是“threading=single”版本。
(6)有“s”的为“runtime-link=static”版本,没有的则是“runtime-link=shared”版本。
(7)有“gd”的为debug版本,没有的则是release版本。
(8)全部的库都含有boost库的版本号结尾(好比1_56,其中的"."如下划线"_"代替)
来源:http://china.ygw.blog.163.com/blog/static/68719746201152485054104/
最新的boost库已经发布了1.46.1版本,可是我接触的比较晚,去年才开始接触并使用,第一次使用的是1.43版本,并且当时安装的时候没有进行彻底安装(未包含mpi及python,只涉及32位版本)。这几天从新研究了一下完整安装问题,如下针对Windows 7系统(64位)下经过vs2010完整安装boost 1.46.1(32位/64位)进行详细描述。
完整安装boost,须要涉及几个第三方库:
1)Regex所须要的Unicode支持类库---ICU。因为本身是使用C/C++,因此须要icu4c。
2)MPI所须要的类库---Boost的官方站点说须要MPICH或OpenMPI之类的支持,事实上在Windows下老是会提示须要MPIC++,你须要的是Microsoft Cluster Pack SDK,下载并默认安装在C:\ProgramFiles\Microsoft Compute Cluster Pack下。(说明:若是安装Microsoft HPC Pack 2008 SDK或Microsoft Compute Cluster Pack时不是装到默认的路径下,那bjam就会找不到mpic++的路径,这时候能够修改一下mpi.jam(在boost_1_46_1\tools\build\v2\tools目录中): local cluster_pack_path_native = "你的路径")。
3)Python所须要的Python语言库---Python。
可是须要注意,若是选择编译python的话,是须要python语言支持的,应该到python官方主页http://www.python.org/下载安装(因此通常也without)。若是要生成Boost.Python库,须要先下载安装x64版的Python安装包,我用的版本是3.2.3。在使用这个库编写Python扩展DLL时,默认是使用动态库版的Boost.Python,要使用静态版的必须在C++项目中定义BOOST_PYTHON_STATIC_LIB宏,这样就不用在使用或发布扩展时带着boost_python-vc90-mt-1_50.dll一块儿了,固然扩展DLL的尺寸会大些,若是作实验不必这样,编译又慢生成的文件也大。
如下先分步描述相关第三库的安装过程:
1)ICU4C
a)当前icu4c最高版本为4.8,下载的源代码包为icu4c-4_8-src.tgz(我的偏向于经过源代码编译生成,这样会更灵活,好比有问题时能够调试);
b)解压icu4c-4_8-src.tgz文件,进入icu\source\allinone子目录,用vs2010打开allinone.sln解决方案;
c)分别按照Win32(32位程序)/x64(64位程序)下的Debug/Release模式进行编译,其Win32的Debug/Release库文件保存于icu\lib目录,x64的Debug/Release库文件保存于icu\lib64目录。须要注意的是:生成相应的Debug/Release库文件后,须要将相应的lib/lib64目录下.dll及.lib文件备份出来,避免编译下一Release/Debug版本时被覆盖;
d)将编译后的Win32/x64的Debug/Release文件(.lib及.dll文件)依次保存好(好比x86/x64目录下的debug/release子目录),并在x86/x64目录下的debug/release子目录下新建include目录,并将icu4c的头文件依次拷贝一份到对应的include目录中(后面编译boost时须要)。
2)MPI
最最简单的方式,直接进入前述地址下载安装便可。
3)Python
当前Python最高版本为3.2,从3.2版本开始有了Windows的安装包(安装后直接有了相应的头文件、库文件等,无需经由代码编译)。在这里要说声抱歉,直接经由代码编译有不少问题,老是编译不过,因此暂时使用安装包,待后面代码编译经过后再使用代码包。(注意,编译32位boost程序时安装32位的python,编译完成后再卸载,而后再安装64位的python,继续进行64位boost的编译,反之亦然)
至此,安装boost所须要的相关第三方库已经准备完成,如今正式开始boost 1.46.1的安装过程:
1)经过boost网站下载最新的boost源代码包boost_1_46_1.tar.gz并解压;
2)用UltraEdit打开boost_1_46_1\boost_1_46_1\tools\build\v2目录下的user-config.jam文件,并在最后增长两行“using mpi ;”(注意,mpi与;之间有一个空格)、“using python : 3.2 : c:\\python32 ;”(注意,3.2与;之间有一个空格,另外,3.2为python的版本号(只须要主版本号与次版本号),c:\\python32为python的安装目录,windows下须要将路径的\符号转换为\\)
3)经过vs2010的“Visual Studio Command Prompt (2010)”(编译32位)、“Visual Studio X64 Win64 Command Prompt (2010)”(编译64位)菜单项进入vs2010命令行,并进入解压后的boost_1_46_1\boost_1_46_1目录;
4)执行bootstrap.bat命令(只须要执行一次便可);
5)x86/x64下的debug/release编译命令分别是:
a)x86 debug
bjam install --prefix=e:\build\boost\1.46.1\x86\debug toolset=msvc-10.0 variant=debug link=shared address-model=32 threading=multi runtime-link=shared -s ICU_PATH=E:\build\icu4c\4.8\x86\debug
b)x86 release
bjam install --prefix=e:\build\boost\1.46.1\x86\release toolset=msvc-10.0 variant=release link=shared address-model=32 threading=multi runtime-link=shared -sICU_PATH=E:\build\icu4c\4.8\x86\release
c)x64 debug
bjam install --prefix=e:\build\boost\1.46.1\x64\debug toolset=msvc-10.0 variant=debug link=shared address-model=64 threading=multi runtime-link=shared -sICU_PATH=E:\build\icu4c\4.8\x64\debug
d)x64 release
bjam install --prefix=e:\build\boost\1.46.1\x64\release toolset=msvc-10.0 variant=release link=shared address-model=64 threading=multi runtime-link=shared -sICU_PATH=E:\build\icu4c\4.8\x64\release
6)其中,--prefix设置boost安装目录;stage表示只生成库文件(dll与lib文件);toolset指定编译器,vs2010就是msvc-10.0,vs2005/vs2008分别是msvc-8.0与msvc-9.0;variant决定编译什么版本;link决定使用静态库仍是动态库,shared是动态库,static是静态库;address-model决定地址长度,即32仍是64位程序;threading决定使用单线程(single)仍是多线程(multi)库;runtime-link决定是静态(static)仍是动态(shared)连接C/C++标准库;-s ICU_PATH设置icu4c的路径;install会生成包含头文件的include目录。
至此,windows 7(64位)系统下使用vs2010彻底编译boost 1.46.1完成(含x86/x64的debug与release版本)。