Boost 1.48.0编译 vs2010

来源:互联网 发布:the affair知乎 编辑:程序博客网 时间:2024/05/10 23:26
 

1. 至http://www.boost.org/users/history/version_1_48_0.html下载boost最新版1.48.0;

2. 解压缩后,运行bootstrap.bat批处理文件,得到bjam.exe;

3. 进入VS2008的Command Prompt (方法:Tools -> Visual Studio 2008 Command Prompt),转到boost目录。(例如,我的boost目录:D:\boost_1_48_0)

4. 输入“bjam --toolset=msvc-10.0 --build-type=complete stage”后,等待约1小时,完成编译。编译成的lib文件,放在stage\lib下,形如“libboost_program_options-vc90-sgd-1_48.lib”.

备注:对于一般使用,可以选择编译boost库(毕竟完整编译需要时间还是比较长的),例如我一般编译如下几个boost常用库system, thread, date_time, filesystem, serialization,则相应的bjam命令如下:

bjam --toolset=msvc-10.0 architecture=x86 address-model=64 --with-system --with-thread --with-date_time --with-filesystem --with-serialization

另外一个说明 

4.设定编译环境(加入红色字体)  
  修改user-config.jam (d:\boost\boost_1_43_0\tools\build\v2\user-config.jam) 的MSVC configuration
  # MSVC configuration
  
  # Configure msvc (default version, searched in standard location
  # and PATH).
  # using msvc ;
  using msvc : 10.0 : : <compileflags>/wd4819 <compileflags>/D_CRT_SECURE_NO_DEPRECATE <compileflags>/D_SCL_SECURE_NO_DEPRECATE <compileflags>/D_SECURE_SCL=0 ;

5.將目录cd到d:\boost\boost_1_43_0\下执行
(1) 编译boost库
bjam --without-python --toolset=msvc-10.0 --build-type=complete --prefix="d:\boost\boost_1_43_0" stage

运行完后(弹出输入提示符)
(2) 则安装,输入:
bjam --with-python --toolset=msvc-10.0 --build-type=complete --prefix="d:\boost\boost_1_43_0" install

6.设定vs2010环境。(注:在2010环境下这步,在项目-->右键属性-->VC++ Directories 中去填写对应路径 )
  Tools -> Options -> Projects and Solutions -> VC++ Directories
  在Library files加上d:\boost\boost_1_43_0\lib
  在Include files加上d:\boost\boost_1_43_0\include

编译完的lib可能多出lib 我是手工重命名的,去掉lib就行

其中:msvc-9.0代表编译成VC9.0(即VS2008)版本,对应的msvc-10.0代表编译成VC10.0(即VS2010)版本; address-model=64代表编译成64位版本,如省略此项,默认为编译成32位版本。


在vs2010下编译boost

注意红色大字体


boost最新版本1.44已经支持vs2010,然而直接下载编译会发现一堆bug;

首先由bootstrap编译bjam的时候就会碰钉子,典型的错误就是:

Failed to build Boost.Jam build engine.
Please consult bjam.log for furter diagnostics.

查看bjam.log后可以发现里面的错误信息:

command.c : fatal error C1033: cannot open program database ''

Technorati 标签boost,c++,编译,vs2010

这个问题在于一个vs编译环境。默认我们都直接进入cmd进行编译,在vs2010环境下这个是行不通的。

其次的错误就是通过bjam编译boost库的时候,会发现编译过程中出现很多fatal,很多库编译不成功;

解决办法: 在开始菜单中,Microsoft Visual Studio 2010\Visual Studio Tools下运行Visual Studio Command Prompt (2010),通过这个cmd进入boost的目录进行bjam的编译以及运行bjam编译boost;

搞定bjam后,在Visual Studio Command Prompt (2010)下直接运行:

bjam --toolset=msvc-10.0 --with-date_time --with-program_options --with-system --with-thread --with-filesystem --with-test --with-regex --with-crypto --with-serialization

然后就可以去喝咖啡了

具体编译参数详见:http://sswflying.spaces.live.com/blog/cns!A1AF9E41EDCAEF99!515.entry

boost库编译方法(zz)

Windows下:

C++代码

  1. bjam.exe --build-type=minimal --with-date_time --with-filesystem --with-program_options --with-regex --with-serialization --with-system --with-thread toolset=msvc-9.0 variant=release link=static threading=multi stage 
bjam.exe --build-type=minimal --with-date_time --with-filesystem --with-program_options --with-regex --with-serialization --with-system --with-thread toolset=msvc-9.0 variant=release link=static threading=multi stage 

Linux下:

C++代码

  1. ./bjam --build-type=minimal --with-date_time --with-filesystem --with-program_options --with-regex --with-serialization --with-system --with-thread variant=release link=static threading=multi stage 
    ./bjam --build-type=minimal --with-date_time --with-filesystem --with-program_options --with-regex --with-serialization --with-system --with-thread variant=release link=static threading=multi stage 


:-) 
//////////////////////////////////////////////// 
许多新人对于编译BOOST感到无从下手,甚至因此而放弃使用BOOST,那真的太可惜了,下面我把一些常用的BOOST编译方法贴于此,同时也作为自己的笔记。 
首先下载bjam.exe,复制到 $BOOST$ 目录下。或者自己生成bjam,打开Visual Studio 2008 命令提示窗口$BOOST$\tools\jam\src,执行 build.bat 会在$BOOST$\tools\jam\src\bin.ntx86 生成 bjam.exe 文件。复制文件 bjam.exe  文件到 $BOOST$\下。 
1.完全编译安装: 
bjam --toolset=msvc install 
完成后会生成一个bin.v2编译时的临时目录,手动删除。生成另一个目录C:\boost,里面为所有的头文件和库文件。头文件目录为boost_1_34_1\boost目录复制过去的。 
2.只编译相应的库文件 
bjam --toolset=msvc stage 
完成后同样会生成bin.v2临时目录。另一个目录为stage文件,里面有对应的库文件。 
3.查看需要编译才能使用的库列表 
bjam --show-libraries 
4.编译特定的库,如只编译regex 
bjam --toolset=msvc --with-regex stage 
生成的库文件在stage目录中。 
5.不编译某个库,如不编译regex 
bjam --toolset=msvc --without-regex stage 
生成的库文件在stage目录中。 
6.编译特定的库,如只编译regex,生成debug,多线程,共享连接版本,并保存在stage。 
bjam --toolset=msvc --with-regex stage debug threading=multi link=shared 
7.生成 mt-sgd 的静态库(runtime-link-static) 
bjam "-sTOOLS=vc-8_0" --with-thread install debug release runtime-link=static 
8.编译regex库。 
bjam --toolset=msvc --with-regex stage debug release threading=multi threading=single link=shared link=static runtime-link=shared runtime-link=static 
boost的安装方法: 
对于DLL版本 
bjam --toolset=msvc link=shared runtime-link=shared threading=multi stage debug release install 
对于lib版本 
bjam --toolset=msvc link=static runtime-link=shared threading=multi stage debug release install 
另外,在$BOOST$\tools\build\v2\user-config.jam找到下面的地文 
# ------------------- 
# MSVC configuration. 
# ------------------- 
# Configure msvc (default version, searched for in standard locations and PATH). 
# using msvc ; 
# Configure specific msvc version (searched for in standard locations and PATH). 
# using msvc : 8.0 ; 
#在这里添加 vs2008 的配置 
using msvc : 9.0 : : /wd4819 /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE  /D_SECURE_SCL=0 ; 
#在这里添加 vs2005 的配置 
using msvc : 8.0 : : <compileflags>/wd4819 <compileflags>/D_CRT_SECURE_NO_DEPRECATE <compileflags>/D_SCL_SECURE_NO_DEPRECATE <compileflags>/D_SECURE_SCL=0 ;    
然后进入 $BOOST$ 目录,执行bjam.exe 编译命令 
//下面的命令的各选项的说明: 
//prefix    将boost安装到的路径(生成的头文件和库文件都会放到该路径中)。 
//重定义以下变量(利用-s设置): 
//VC80_ROOT   vc2005的安装路径,如果未将vc2005安装到默认位置,你必须指定该项。 
//TOOLS         使用的编译工具,vc2005对应的是vc-8_0 
//PYTHON_ROOT   ython的安装目录,如果未将BOOST安装到默认位置,你必须指定该项。 
//BUILD         编译结果选项,默认会生成尽可能多的版本,如调试版/发行版,静态库/动态库,单线程/多线程。 
bjam 命令说明 
Boost.Build V2 (Milestone 12) 
Boost.Jam 03.1.16 
Project-specific help: 
  Project has jamfile at Jamroot 
Usage: 
  bjam [options] [properties] [install|stage] 
  Builds and installs Boost. 
Targets and Related Options: 
  install                 Install headers and compiled library files to the 
  =======                 configured locations (below). 
  --prefix=<PREFIX>       Install architecture independent files here. 
                          Default; C:\Boost on Win32 
                          Default; /usr/local on Unix. Linux, etc. 
  --exec-prefix=<EPREFIX> Install architecture dependent files here. 
                          Default; <PREFIX> 
  --libdir=<DIR>          Install library files here. 
                          Default; <EPREFIX>/lib 
  --includedir=<HDRDIR>   Install header files here. 
                          Default; <PREFIX>/include 
  stage                   Build and install only compiled library files 
  =====                   to the stage directory. 
  --stagedir=<STAGEDIR>   Install library files here 
                          Default; ./stage 
Other Options: 
  --build-type=<type>     Build the specified pre-defined set of variations 
                          of the libraries. Note, that which variants get 
                          built depends on what each library supports. 
                              minimal (default) - Builds the single 
                              "release" version of the libraries. This 
                              release corresponds to specifying: 
                              "release <threading>multi <link>shared 
                              <link>static <runtime-link>shared" as the 
Boost.Build variant to build. 
                              complete - Attempts to build all possible 
                              variations. 
  --build-dir=DIR         Build in this location instead of building 
                          within the distribution tree. Recommended! 
  --show-libraries        Displays the list of Boost libraries that require 
                          build and installation steps, then exit. 
  --layout=<layout>       Determines whether to choose library names 
                          and header locations such that multiple 
                          versions of Boost or multiple compilers can 
                          be used on the same system. 
                              versioned (default) - Names of boost
                              binaries include the Boost version 
                              number and the name and version of the 
                              compiler.  Boost headers are installed 
                              in a subdirectory of <HDRDIR> whose 
                              name contains the Boost version 
                              number. 
                              system - Binaries names do not include 
                              the Boost version number or the name 
                              and version number of the compiler. 
Boost headers are installed directly 
                              into <HDRDIR>.  This option is 
                              intended for system integrators who 
                              are building distribution packages. 
  --buildid=ID            Adds the specified ID to the name of built 
                          libraries.  The default is to not add anything. 
  --help                  This message. 
  --with-<library>        Build and install the specified <library> 
                          If this option is used, only libraries 
                          specified using this option will be built. 
  --without-<library>     Do not build, stage, or install the specified 
                          <library>. By default, all libraries are built. 
Properties: 
  toolset=toolset         Indicates the toolset to build with. 
  variant=debug|release   Select the build variant 
  link=static|shared      Whether to build static or shared libraries 
  threading=single|multi  Whether to build single or multithreaded binaries 
  runtime-link=static|shared     
                          Whether to link to static or shared C and C++ runtime. 
Configuration help: 
  Configuration file at $boost$\tools\build\v2 
  user-config.jam 
  This file is used to configure your Boost.Build installation. You can modify 
this file in place, or you can place it in a permanent location so that it 
does not get overwritten should you get a new version of Boost.Build. See: 
  http://boost.org/boost-build2/doc/html/bbv2/reference.html#bbv2.reference.init 
for documentation about possible permanent locations. 
General command line usage: 
    bjam [options] [properties] [targets] 
  Options, properties and targets can be specified in any order. 
Important Options: 
  * --clean Remove targets instead of building 
  * -a Rebuild everything 
  * -n Don't execute the commands, only print them 
  * -d+2 Show commands as they are executed 
  * -d0 Supress all informational messages 
  * -q Stop at first error 
  * --debug-configuration Diagnose configuration 
  * --debug-building Report which targets are built with what properties 
  * --debug-generator Diagnose generator search/execution 
Further Help: 
  The following options can be used to obtain additional documentation. 
  * --help-options Print more obscure command line options. 
  * --help-internal Boost.Build implementation details. 
  * --help-doc-options Implementation details doc formatting. 
编译所有版本: 
bjam --toolset=msvc-8.0 --prefix=$lib-and-dll-out-dir$ --build-type=complete install 
等待编译完成. 
设置开发环境: 
打开VS2005 选择 工具->选项->vc++目录 
设置包含文件目录$lib-and-dll-out-dir$\include\boost-1_37\boost
设置引用文件目录:$lib-and-dll-out-dir$\lib 
完成.可以使用了.



STLport

VS2010 编译 Boost 1.4.7 With STLport 5.2.1


生成 bjam 工具

      在 vs2010 命令提示工具下打开 Boost 目录,键入 bootstrap 即可在Boost目录下生成 bjam 工具。

配置 STLport 目录

      如果需要编译使用 STLport 的 boos t库,可以使用 stdlib=stlport 这个命令,但是需要修改文件才可以成功。在%boostDir%\tools\build\v2 目录下找到 user-config.jam 并使用文本工具打开。找到如下内容:

1 # Configure specifying location of both headers and libraries explicitly.
2 # using stlport : : /usr/include/stlport /usr/lib ;

修改成如下内容:

1 # Configure specifying location of both headers and libraries explicitly.
2 using stlport : 5.2.1 : %STLportDir%/stlport : %STLportDir%/lib ;

这里需要注意,5.2.1 是 STLport 版本号,3个冒号(:)两边都得有空格,分号(;)前面也必须有空格。

编译 Boost

      修改好 user-config.jam 就可以使用 bjam 加 stdlib=stlport 参数 编译 Boost 了。



VS2010 编译 STLport 5.2.1 With Boost 1.4.7


配置 STLport 编译选项

      STLport 本身并没有提供 VS2010 的编译配置选项,如果需要使用 VS2010 编译,可以参照这篇文章对源文件进行修改或下载文章中提供的文件包覆盖STLport目录里的文件。这时STLport的配置选项里面多了 msvc10 和 msvc10x64 这两个配置选项,使用这两个配置选项即可在 VS2010 的环境下编译STLport。(使用时把 %boostDir% 替换成 Boost 所在目录)

1 configure msvc10 --use-boost %boostDir%      --编译32位的STLport2 configure msvc10X86 --use-boost %boostDir%   --编译64位的STLport

      这样直接编译支持Boost的STLport会报错,需要修改源文件。打开 "stlport\stl\type_traits.h" 找到

1 #ifdef _STLP_USE_BOOST_SUPPORT  2 #  include <stl/boost_type_traits.h>  3 #  include <boost/type_traits/add_reference.hpp>  4 #  include <boost/type_traits/add_const.hpp>  5 #endif /* _STLP_USE_BOOST_SUPPORT */

修改为 

1 #ifdef _STLP_USE_BOOST_SUPPORT2 #  include <stl/boost_type_traits.h>3 #  include <boost/type_traits/add_reference.hpp>4 #  include <boost/type_traits/add_const.hpp>5 #  include <boost/type_traits/remove_const.hpp>  /*新添加此行*/6 #endif /* _STLP_USE_BOOST_SUPPORT */

这样进行编译就可以顺利通过。

其他编译选项

[-X] 

使用交叉编译,一般不使用此选项.

[--with-static-rtl]

表示使用static C/C++ runtime library (libc.lib family,项目属性选择/MT会用到这个产生的lib)

[--with-dynamic-rtl]

表示使用dynamic C/C++ runtime library (msvcrt.lib family,项目属性选择/MD会用到这个产生的lib)

使用 STLport

      使用STLport除了向项目添加 STLport 的头文件目录和 Lib 目录以外还有如下宏定义配合使用。

1 #define _STLP_USE_STATIC_LIB    // 使用 STLport 静态库  2 #define _STLP_USE_DYNAMIC_LIB   // 使用 STLport 动态库3 #define _STLP_DEBUG             // STLport 启用 Debug 模式下的检查功能  4 #define _STLP_USE_BOOST_SUPPORT // STLport 与 Boost 库配合使用 
 
 
 
摘自:http://blog.163.com/sweet_hard/blog/static/666568382011102483854916/
原创粉丝点击