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

来源:互联网 发布:学校预算编制软件 编辑:程序博客网 时间:2024/06/04 20:09
  • 下载 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=/home/i5/boost-1.59.0或者,修改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")# optionset(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()
0 0