vs2013 boost库编译小结

来源:互联网 发布:淘宝买家贷款5万怎么贷 编辑:程序博客网 时间:2024/05/01 16:52

转自:http://m.blog.csdn.net/blog/chenjh213/42265605

#编译boost库  32位编译:

#从开始菜单启动Visual Studio 2013的vs2013 命令行,进入boost所在目录,运行bootstrap.bat
编译命令:
bjam.exe stage --toolset=msvc-12.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-serialization --without-wave --without-test --without-program_options --without-serialization --without-signals --stagedir="vc12_x86" link=static runtime-link=shared threading=multi debug release
#toolset:指定编译器,可选的如borland、gcc、msvc(VC6)、msvc-10.0(VS20010)
#vs2008 : msvc-9.0,vs2010 : msvc-10.0, VS2012、VS2013是msvc-12.0
#stagedir:表示编译生成文件的路径。
#build-dir:编译生成的中间文件的路径。这个本人这里没用到,默认就在根目录(D:\boost\boost_1_57_0)下,目录名为bin.v2(删掉),等编译完成后可将这个目录全部删除(没用了),所以不需要去设置。
#without/with:选择不编译/编译哪些库。
#address-model:要有address-model=64属性,如果没有这个属性的话,会默认生成32位的平台库,加入这个选项才能生成64位的DLL。
#threading:单/多线程编译。一般都写多线程程序,当然要指定multi方式了;如果需要编写单线程程序,那么还需要编译单线程库,可以使用single方式。
#静态库版link=shared,动态库link=shared
#runtime-link:动态/静态链接C/C++运行时库。同样有shared和static两种方式,这样runtime-link和link一共可以产生4种组合方式,各人可以根据自己的需要选择编译。一般link只选static的话,只需要编译2种组合即可,即link=static runtime-link=shared和link=static runtime-link=static。
#debug/release:编译debug/release版本。一般都是程序的debug版本对应库的debug版本,所以两个都编译。
#64位编译:
从开始菜单启动Visual Studio 2013的vs2013 x64兼容工具命令行,然后转到boost根文件夹,运行bootstrap.bat生成x64版的bjam.exe。
在编译命令中加入address-model=64属性
#还有人总结windows下boost库的命名特点:
link=static runtime-link=static 得到 libboostxxxxx.lib
link=shared runtime-link=shared 得到 boostxxxx.lib 和 boostxxxx.dll
由以上的文件夹层次结构基本就可以得出结论:
1、以“lib”开头的是“link-static”版本的,而直接以“boost”开头的是“link-shared”版本的。
2、有“d”的为debug版本,没有的则是release版本。
3、有“s”的为“runtime-link-static”版本,没有的则是“runtime-link-shared”版本。
4、有“mt”的为“threading-multi”版本,没有的则是“threading-single”版本。
#设定vs2013环境。
(在项目-->右键属性-->C/C++)附加包含目录:如:F:/boost_1.57_0
链接器:附加库目录:(编译生成文件的路径)如:F:/boost_1.57_0/stage/bin
附加依赖项:(项目所需编译库)
如果编译成Debug则包含:libboost_regex-vc120-mt-gd-1_57.lib(举例)
如果编译成Release则包含:libboost_regex-vc120-mt-1_57.lib

或者添加#pragma comment(lib, "libboost_regex-vc120-mt-gd-1_57.lib")附加链接库




#define BOOST_LIB_DIAGNOSTIC

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

测试一下:

<pre name="code" class="cpp">#include "stdafx.h"#include <boost/regex.hpp>#include <boost/asio.hpp>#include <iostream>#pragma comment(lib, "libboost_date_time-vc120-mt-gd-1_57.lib")#pragma comment(lib, "libboost_system-vc120-mt-gd-1_57.lib")int _tmain(int argc, _TCHAR* argv[]){boost::regex reg("[0-9]+");//lib库在项目附加依赖项中添加了std::cout << boost::regex_match("123", reg) << std::endl;boost::asio::io_service io;system("PAUSE");return 0;}



0 0
原创粉丝点击