boost安装说明

1. 从www.boost.org下载boost压缩包,解压到d:\boost.
   Boost库的大部分组件不需要编译,直接包含其头文件即可。Boost的头文件后缀为hpp
   linux下解压 tar -xzf boost_1_63_0.tar.gz
  
2. 获取bjam程序。
   运行./bootstrap.sh或者bootstrap.bat


   
3. 编译boost
   a. 完整编译,生成所有debug,release版本的静态库和共享库。编译后产物位于boost\bin.v2
   windows下:bjam --toolset=msvc --build-type=complete stage
   linux下:  bjam --toolset=gcc  --build-type=complete stage
   完整编译需花费数小时和数十GB硬盘空间。
   b. 部分编译,使用with编译某个库,使用without不编译某个库。例如(默认共享库)
   编译date_time库:bjam --toolset=msvc-10.0 --with-date_time --build-type=complete stage address-model=64 [link=shared(共享库)][link=static(静态库)]
编译thread库:   bjam --toolset=msvc-10.0 --with-thread    --build-type=complete stage address-model=64 [link=shared(共享库)][link=static(静态库)]
编译system库:   bjam --toolset=msvc-10.0 --with-system    --build-type=complete stage address-model=64 [link=shared(共享库)][link=static(静态库)]
编译regex 库:   bjam --toolset=msvc-10.0 --with-regex     --build-type=complete stage address-model=64 [link=shared(共享库)][link=static(静态库)]
 
vs2003 : msvc-7.1
   vs2005 : msvc-8.0
   vs2008 : msvc-9.0
   vs2010 : msvc-10.0
   
   linux
   编译date_time库:./bjam --toolset=gcc --with-date_time address-model=64
编译thread库:   ./bjam --toolset=gcc --with-thread    address-model=64
编译system库:   ./bjam --toolset=gcc --with-system    address-model=64
编译regex 库:   ./bjam --toolset=gcc --with-regex     address-model=64
编译chrono库:   ./bjam --toolset=gcc --with-chrono    address-model=64
 
bjam选项:
--stagedir="" 表示编译要生成的文件的路径
address-model=64 有这个表示生成64位的库,没有这个选项就是32位的库
 
 
Android NDK交叉编译
1. 在liunx下使用Android NDK生成工具链,并将工具链的bin加入到环境变量PATH中
export PATH="/home/yxhuang3/android-toolchain-9/bin":$PATH
2. 解压boost
tar -xzf boost_1_55_0.tar.gz
3.运行bootstrap.sh,生成project-config.jam文件
./bootstrap.sh
4.修改生成的project-config.jam文件(共五处),具体可以参照


   using gcc : arm : arm-linux-androideabi-gcc ;


   option.set prefix :(交叉编译器所在位置);


   option.set exec-prefix :(交叉编译器所在位置)/bin ;


   option.set libdir :(交叉编译器所在位置)/lib ;


   option.set includedir :(交叉编译器所在位置)/include ;
   
修改后的project-config.jam文件如下:
# Boost.Build Configuration
# Automatically generated by bootstrap.sh


import option ;
import feature ;


# Compiler configuration. This definition will be used unless
# you already have defined some toolsets in your user-config.jam
# file.
if ! gcc in [ feature.values <toolset> ]
{
    using gcc : arm : arm-linux-androideabi-g++ -D_LITTLE_ENDIAN ;
}


project : default-build <toolset>gcc ;


# Python configuration
using python : 2.7 : /usr ;


path-constant ICU_PATH : /usr ;




# List of --with-<library> and --without-<library>
# options. If left empty, all libraries will be built.
# Options specified on the command line completely
# override this variable.
libraries =  ;


# These settings are equivivalent to corresponding command-line
# options.
option.set prefix : /home/yxhuang3/android-toolchain-9 ;                  
option.set exec-prefix : /home/yxhuang3/android-toolchain-9/bin ;         
option.set libdir : /home/yxhuang3/android-toolchain-9/sysroot/usr/lib ;              
option.set includedir : /home/yxhuang3/android-toolchain-9/sysroot/usr/include ;


# Stop on first error
option.set keep-going : false ;




5. 编译 
 编译thread库 ./bjam stage --with-thread --layout=tagged link=shared runtime-link=shared threading=multi
 此时会出现“ld cannot find -lrt”的错误,解决办法:
 编辑tools/build/v2/tools/gcc.jam文件,注释掉“libs = rt”。
  case * :
  {
      option = -pthread ;
      libs = rt ;   <--Comment this line
  }
  
6. 运行时出现错误cannot locate symbol "_ZNSsC1EPKcRKSaIcE" referenced by "libboost_system-mt.so.1.53.0"
   using gcc : arm : arm-linux-androideabi-g++ ;
   
7. 编译其他boost库
   ./bjam stage --with-system    --layout=tagged link=shared runtime-link=shared threading=multi  cflags=-fPIE -pie cxxflags=-fPIE -pie linkflags=-fPIE -pie
   ./bjam stage --with-thread    --layout=tagged link=shared runtime-link=shared threading=multi  cflags=-fPIE -pie cxxflags=-fPIE -pie linkflags=-fPIE -pie
   ./bjam stage --with-date_time --layout=tagged link=shared runtime-link=shared threading=multi  cflags=-fPIE -pie cxxflags=-fPIE -pie linkflags=-fPIE -pie
   ./bjam stage --with-regex     --layout=tagged link=shared runtime-link=shared threading=multi  cflags=-fPIE -pie cxxflags=-fPIE -pie linkflags=-fPIE -pie
   好像不需要chrono库
   ./bjam stage --with-chrono    --layout=tagged link=shared runtime-link=shared threading=multi  cflags=-fPIE -pie cxxflags=-fPIE -pie linkflags=-fPIE -pie
   好像不需要atomic库   
   ./bjam stage --with-atomic    --layout=tagged link=shared runtime-link=shared threading=multi  cflags=-fPIE -pie cxxflags=-fPIE -pie linkflags=-fPIE -pie
   
8. 编译date_time出现错误
   "The file boost/detail/endian.hpp needs to be set up for your CPU type."
   解决方法:添加-D_LITTLE_ENDIAN编译选项。编辑project-config.jam,"using gcc : arm : arm-linux-androideabi-g++ -D_LITTLE_ENDIAN ;"
   
9. 编译chrono时出现错误
   error: cannot find -lrt
   collect2: ld returned 1 exit status
   "arm-linux-androideabi-g++" "-D_LITTLE_ENDIAN"    -o "bin.v2/libs/chrono/build/gcc-arm/release/threading-multi/libboost_chrono-mt.so.1.53.0" -Wl,-h -Wl,libboost_chrono-mt.so.1.53.0 -shared -Wl,--start-group "bin.v2/libs/chrono/build/gcc-arm/release/threading-multi/chrono.o" "bin.v2/libs/chrono/build/gcc-arm/release/threading-multi/thread_clock.o" "bin.v2/libs/chrono/build/gcc-arm/release/threading-multi/process_cpu_clocks.o" "bin.v2/libs/system/build/gcc-arm/release/threading-multi/libboost_system-mt.so.1.53.0"  -Wl,-Bstatic  -Wl,-Bdynamic  -Wl,--end-group -pthread -lrt -lpthread
   解决方法:将上面的编译指令去掉"-lrt"后直接执行,编译结果位于bin.v2中
   
   
10. 添加PIE编译选项
    cflags=-fPIE -pie cxxflags=-fPIE -pie linkflags=-fPIE -pie
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值