如何编译&使用boost库?

本文详细介绍了如何使用Visual Studio 2005编译Boost库为动态或静态库,并提供了编译命令及参数说明。同时,文中还列举了在不同编译配置下所需的库文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 编译

1.1. 下载地址: http://www.boost.org/
1.2. VS2005编译boost_1_55_0
1.2.1. 使用vs2005的命令行执行:...\boost_1_55_0\bootstrap.bat
1.2.2. 编译动态库
bjam install stage --toolset=msvc-8.0 --stagedir= "C:\Boost\boost_vc_80"  link=shared runtime-link=shared threading=multi debug release 

1.2.3. 编译静态库

bjam install stage --toolset=msvc-8.0 --stagedir= "D:\Boost\boost_vc_80"  link= static  runtime-link= static  threading=multi debug release  

各种参数详解:
stage:表示只生成库(dll和lib)
install:还会生出包含的头文件
--toolset=msvc-8.0:指定编译器版本,8.0为vs2005,其他VS类推。
--stagedir:指定编译后存放的目录
link:生成动态库/静态库。动态库(shared),静态库(static)
runtime-link:动态/静态C/C++运行时库,同样有shared和static两种组合方式。这样共有4种组合方式,个人根据自己需要选择。
threading:单/多线程,一般都是多线程程序,当然multi了。
debug/release:编译版本,一般2个都需要。

2. 使用

使用静态库:
//#define BOOST_ALL_DYN_LINK
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
使用静态库连接时,仅需要包含的lib为:
debug版:libboost_system-vc80-mt-gd-1_55.lib等一系列包含gd的库。
release版本:libboost_system-vc80-mt-1_55.lib 等一系列不包含gd的库。

使用动态库链接:
#define BOOST_ALL_DYN_LINK
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
使用动态库链接时,仅需要包含的lib为:
debug版:boost_system-vc80-mt-gd-1_55.lib,同时在生成的exe加入boost_system-vc80-mt-gd-1_55.dll
release版:boost_system-vc80-mt-1_55.lib,同时在生产的exe路径下加入boost_system-vc80-mt-1_55.dll

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 2015/3/26第2次编辑
当你将
bjam install stage --toolset=msvc-8.0 --stagedir="C:\Boost\boost_vc_80" link=shared runtime-link=shared threading=multi debug release 
里面的"install"和"-stagedir="C:\Boost\boost_vc_80"去掉的时候,会在当前夹子下面默认生成一个stage文件夹存放生成的库。

参考:
1. http://blog.youkuaiyun.com/liukang0618/article/details/9149881
2. http://chenrongya.blog.163.com/blog/static/874741962010102041157963/
3. http://blog.youkuaiyun.com/alex_my/article/details/17630685

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值