Boost 的编译(交叉)安装 & cmake find_package(Boost)

  • 下载 boost 1.59的源码,执行:
./bootstrap.sh
  • 编辑文件 project-config.jam,用 “using gcc : arm : arm-linux-gnueabihf-g+±4.8” 替换 “using gcc”, 行尾的分号前有个空格

  • 执行编译安装:

./bjam install toolset=gcc-arm --prefix=/path/to/install  --disable-sNO_ZLIB=1 -sNO_BZIP2=1 --without-python

如果需要编译 Boost.Coroutine 和 Boost.Context (For Arm):
./bjam install toolset=gcc-arm architecture=arm address-model=32 abi=aapcs binary-format=elf --disable-sNO_ZLIB=1 -sNO_BZIP2=1 --without-python --prefix=/path/to/install

或者,修改project-config.jam后, 对4核cpu ( b2 比 bjam 新一点):
./b2 install toolset=gcc-arm --prefix=/path/to/install  --disable-sNO_ZLIB=1 -sNO_BZIP2=1 --without-python -j 4

如果只需要编译某几个特定的库:

cd boost
./bootstrap.sh --with-libraries=coroutine,context,thread,system
./b2 -j4
// where `-j4 specifies a parallel build using 4 jobs. 
// You may want to increase or decrease the number of parallel jobs, 
// depending on the number of cores available on your system. 
// If you prefer to build all Boost libraries, then leave out the --with-libraries option.

若使用cmake编译项目,编辑 FindBoost.cmake 文件
vi /usr/share/cmake-2.8/Modules/FindBoost.cmake
在前面添加:

SET(Boost_ADDITIONAL_VERSIONS "1.59" "1.59.0")
SET(BOOST_ROOT "/path/to/boost1.59.0")

这样 find_package 就可以找到新的boost库了。

或者直接在项目中添加,例如:

SET(Boost_ADDITIONAL_VERSIONS "1.59" "1.59.0")
SET(BOOST_ROOT "/usr/local/boost1.59.0")

# option
set(Boost_USE_STATIC_LIBS OFF) 
set(Boost_USE_MULTITHREADED ON)  
set(Boost_USE_STATIC_RUNTIME OFF) 

find_package(Boost 1.59.0 COMPONENTS filesystem regex REQUIRED)   # 最好是加上REQUIRED,否则找不到某些库也不会报错,链接会出问题

if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS}) 
    add_executable(progname file1.cxx file2.cxx) 
    target_link_libraries(progname ${Boost_LIBRARIES})
endif()
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值