1、运行VS2003工具里的 “Visual Studio .NET 2003 命令提示"
2、在命令行模式下,cd 进入需要编译的Boost C++ Libraries 下面具体类库的Build目录
3、运行 nmake vc71.mak
例子:
cd D:/MyProject/ShareCode/boost_1_35_0/libs/regex/build
nmake vc71.mak
and install
boost库的编译其实很简单,关键是要自己尝试一下。
从网上的一些文章中摘录出其中最关键的步骤,再加上自己的实践,总结出如下文字,在此存档。
===================================================
boost编译步骤:
1.代码下载 - 官方网站:http://www.boost.org
在官方网站下载代码的压缩包,解压到本地目录。
比如boost_1_38_0.zip,解压到 "e:/boost_1_38_0"。
2. 准备工作
下载boost 编译工具 boost-jam-3.1.17-1-ntx86.zip。
下载地址google一下吧。http://sourceforge.net/projects/boost
3. 编译
1):打开“开始”菜单,选择“运行”,输入cmd,进入控制台窗口,进入boost安装源路径e:/boost_1_38_0。
2):cmd中输入:
bjam install --toolset=borland --prefix="E:/boost_1_38_0" debug --with-date_time --with-regex
-- 是两个连续的减号,=前后均不能夹带空格,除路径之外,参数都是小写字母。
--toolset 表示采用borland编译。如果用VC编译,则改为 --toolset=msvc
debug表示编译“调试版”。
--with 指定要编译的模块
3):回车后,出现大量奇怪文字,最后能看到以下内容,就表示成功完成编译:
...failed updating 2 targets.
...skipped 31 targets...
...updated 341 targets...
4). release版本
bjam install --toolset=borland --prefix="E:/boost_1_38_0" release --with-date_time --with-regex
改变的是“debug”更换为“release”。回车后开始release的boost库编译。
5).有时不知道编译器到底需要什么版本的lib,可以完整编译boost:
bjam install --toolset=borland --prefix="E:/boost_1_38_0" debug(或release)--build-type=complete
这样会编译出所有debug和release的lib库。
6). 库的使用
编译完成后,E:/boost_1_38_0 目录下,可以看到两个子目录:"include"和"lib",前者保存着所有采用纯头文件形式提供的boost代码文件;后者则是所有编译出的库文件。.dll, .lib
7). 结束
打开C++Builder2007.
Project-Default Options-C++Builder设置。在Include Path添加前面的"include/boost-1_38"所在的目录,在Library Path添加“lib”所在的目录。
C++Options-Paths and Directories.同上设置。
VC的设置众所周知,就不说了。
另附 bjam 参数
--build-dir=<builddir> 编译的临时文件会放在builddir里(编译完就可删除)
--stagedir=<stagedir> 存放编译后库文件的路径,默认是stage
--build-type=complete 编译所有版本(确切地说是相当于:variant=release, threading=multi;link=shared|static;runtime-link=shared)
variant=debug|release 编译什么版本(Debug or Release?)
link=static|shared 使用静态库还是动态库。
threading=single|multi 单线程还是多线程库。
runtime-link=static|shared 决定是静态还是动态链接C/C++标准库。
--with-<library> 只编译指定的库,如输入--with-regex就只编译regex库了。
--show-libraries 显示需要编译的库名称
===============================================================
1、下载boost包
从boost网站下载boost_1_36_0.tar.gz
2、解压
假设解压到D:/,那么Boost根目录就是D:/boost_1_36_0
3、构建bjam
在“Boost根目录/tools/jam”下,运行build_dist.bat(Linux:build_dist.sh)
将stage/bin.bin.ntx86/bjam.exe(Linux:stage/bin.linuxx86_64/bjam)拷贝到Boost根目录,创建快捷方式,符号链接也可以
4、构建boost库
bjam -toolset=msvc --build-type=complete install
(Linux:./bjam -toolset=gcc --build-type=complete install)
其他配置
1、安装路径:--prefix=<PREFIX>
默认:C:/Boost(Linux:/usr/local)
2、库文件安装路径:--libdir=<DIR>
默认:<EPREFIX>/lib
3、头文件安装路径:--includedir=<HDRDIR>
默认:<PREFIX>/include
4、构建类型:--build-type=<type>
debug release shared static mutil
5、中间文件存放路径:--build-dir=DIR
默认:Boost根目录
6、指定编译器:--toolset=toolset
msvc Microsoft Visual Studio
gcc Linux
可以指定版本,如
msvc-7.1 Microsoft Visual Studio 2003
msvc-8.0 Microsoft Visual Studio 2005
7、只构建指定库:--with-<library>
8、不构建指定库:--without-<library>
=========================test==============================
bjam install --toolset=msvc --prefix="E:/__Library__/boost_1_39_0" debug mutil --with-date_time --with-regex
bjam --with-system --with-thread --with-date_time --with-regex --with-serialization stage
///
bjam install --toolset=msvc-7.1 --prefix="E:/__Library__/boost_1_39_0" --build-type="debug <threading>multi <link>shared <link>static <runtime-link>shared" --with-system
bjam install --toolset=msvc-7.1 --prefix="E:/__Library__/boost_1_39_0" debug --build-type=complete --with-system --with-thread --with-date_time --with-regex --with-serialization stage
bjam install --toolset=msvc-7.1 --prefix="E:/__Library__/boost_1_39_0" release --build-type=complete --with-system --with-thread --with-date_time --with-regex --with-serialization stage
LinuX
make lib gcc43
./bjam install --toolset=gcc --prefix="/home/hjz/boost_1_39_0" debug --build-type=complete --with-system --with-thread --with-date_time --with-regex --with-serialization stage
make *.cpp.
c++ -I /home/hjz/boost_1_39_0 example.cpp -o example ~/boost_1_39_0/lib/libboost_regex-gcc43-mt-d-1_39.a
asio
c++ -I /home/hjz/boost_1_39_0 LinuX_HttpClient.cpp -o /
lhc ~/boost_1_39_0/lib/libboost_regex-gcc43-mt-d-1_39.a /
~/boost_1_39_0/lib/libboost_system-gcc43-mt-d-1_39.a /
~/boost_1_39_0/lib/libboost_thread-gcc43-mt-d-1_39.a /
~/boost_1_39_0/lib/libboost_date_time-gcc43-mt-d-1_39.a /
~/boost_1_39_0/lib/libboost_serialization-gcc43-mt-d-1_39.a /
~/boost_1_39_0/lib/libboost_wserialization-gcc43-mt-d-1_39.a
D:/__Library__/boost_1_42_0>bjam --toolset=intel-win32 --prefix="d:/__Library__/boost_1_42_0" debug --build-type=complete --with-thread stage
D:/boost_1_42_0>bjam "-sTools=vc-7_1-stlport" "-sSTLPORT_PATH=D:/STLport-5.2.1/STLport-5.2.1/stlport" "-sSTLPORT_VERSION=5.2.1" --prefix="E:/__Library__/boost_1_39_0" debug --build-type=complete --with-thread stage
1. 到 http://www.stlport.com/ 下载 ,最新的版本是STLport-5.1.3,并解压到
C:/STLport-5.1.3
2. 解压后, 包含几个目录和文件, 如 doc, src, build 等:
3. 修改"C:/Program Files2/Microsoft Visual Studio .NET 2003/Common7
/Tools/vsvars32.bat"文件,
在@set INCLUDE=的后面添加“C:/STLport-5.1.3/stlport;”
在@set LIB=的后面添加“D:/STLport-5.1.3/lib;”
4. 打开控制台窗口 cmd , 执行:
cd C:/STLport-5.1.3/stlport
"C:/Program Files2/Microsoft Visual Studio .NET 2003/Common7/Tools/vsvars32.bat"
这样,就可以在该控制台窗口里运行 nmake.exe了。
5. 不要关闭控制台窗口,运行如下命令:
cd D:/STLport-5.1.3/build/lib // 切换到make目录
configure -c msvc71 // 指定编译器. --help 可以看到其它选项
nmake /fmsvc.mak
nmake /fmsvc.mak install
6. 打开vs2003,选择菜单“工具”-》“选项”,弹出对话框,选择左边列表框的
“项目”-》“VC目录”:包含文件添加“D:/STLport-5.0-0125/stlport”,
库文件添加“D:/STLport-5.0-0125/lib”,分别将它们移到最上一条。
这样,就不必在以后的每个项目中显示指定包含路径和库路径.
7. 测试是否使用了STLPort.
用 vs2003 新建一个项目. 使用 <vector> .
确保 项目属性/C/C++代码生成/运行时库 = 单线程 或 单线程调试.
然后 build 该项目, 会看到大量link错误: 类似
无法解析的外部符号 "public: bool __thiscall stlpmtx_std::......
若将 项目属性 改为多线程后, build 成功.
这说明 STLPort 已经起作用.
这同时说明, STLPort 库生成的时候只针对多线程. 因此使用 STLPort
的项目必须使用多线程.
当然, STLPort 库也可以生成针对单线程的. 在编译STLPort库前,
查看 configure --help 可以找到答案.
using stlport : 5.2.1 : D://STLport-5.2.1//stlport : D://STLport-5.2.1//lib ;
bjam stdlib=stlport --toolset=msvc-7.1 --prefix="D:/boost_1_42_0" debug --build-type=complete --with-thread stage
Feature | Allowed values | Notes |
---|---|---|
variant | debug,release | |
link | shared,static | Determines if Boost.Build creates shared or static libraries |
threading | single,multi | Cause the produced binaries to be thread-safe. This requires proper support in the source code itself. |
address-model | 32,64 | Explicitly request either 32-bit or 64-bit code generation. This typically requires that your compiler is appropriately configured. Please refer to the section called “C++ Compilers” and your compiler documentation in case of problems. |
toolset | (Depends on configuration) | The C++ compiler to use. See the section called “C++ Compilers” for a detailed list. |
include | (Arbitrary string) | Additional include paths for C and C++ compilers. |
define | (Arbitrary string) | Additional macro definitions for C and C++ compilers. The string should be either SYMBOL or SYMBOL=VALUE |
cxxflags | (Arbitrary string) | Custom options to pass to the C++ compiler. |
cflags | (Arbitrary string) | Custom options to pass to the C compiler. |
linkflags | (Arbitrary string) | Custom options to pass to the C++ linker. |
runtime-link | shared,static | Determines if shared or static version of C and C++ runtimes should be used. |