Build boost 1.66.0 with c++11


轉載 https://www.jianshu.com/p/9efabc5faf3e

build boost

以1.66.0為例, build boost很簡單了:
build b2

./bootstrap.sh --prefix=/opt/boost
會生成 b2 bjam project-config.jam.
--prefix 作用在 project-config.jam 里, 會在 build 時設置 include 和 lib 的安裝目錄
option.set prefix : /opt/boost ;
option.set exec-prefix : /opt/boost ;
option.set libdir : /opt/boost/lib ;
option.set includedir : /opt/boost/include ;
build boost
include 和 build 好的 libs 會安裝到之前指定的 folder 中

./b2 install
提升 build 速度, 可以制定 build thread number (jobs)

./b2 -j8 install
gcc5.4 默認是不開啟 c++11 的, 某些依賴 c++11 特性的代碼不會生效. 部分 lib 依賴 c++11 的功能, 如果不支持此特性, 就不會被編譯. 比如 fiber 在沒有開啟 c++11 支持下就不會被編譯.
所以需要打開 c++11 的支持, gcc5.4 下, 只打開 --std=c++11 是不能編譯fiber的, 使用 --std=c++14 或者 --std=c++17 可以成功

./b2 cxxflags="--std=c++17" -j8 install
b2 常用的 property 還有
variant=debug|release Select the build variant
link=static|shared Whether to build static or shared libraries
在根目錄下, 默認 build release 下 static 和 shared

build one boost library

如果需要單獨 build 某 library, 可以在 /libs/***/build/ 下 run b2 進行編譯
以 fiber 為例

cd libs/fiber/build
../../../b2 cxxflags="--std=c++17" -j8 variant=release link=shared install
build 產生的中間文件在 bin.v2
cj@ubuntu:/opt/boost_1_64_0/bin.v2/libs/fiber$ tree . └── build └── gcc-5.4.0 └── release └── threading-multi ├── algo │ ├── algorithm.o ... ├── libboost_fiber.so.1.64.0 ... └── timed_mutex.o

clean cached cxx11_** result

在 b2 build 開始后, 首先輸出的是 configuration checks:
Performing configuration checks - 32-bit : no (cached) - 64-bit : yes (cached) ... - symlinks supported : yes (cached) - C++11 mutex : yes (cached) - Boost.Config Feature Check: cxx11_auto_declarations : yes (cached) - Boost.Config Feature Check: cxx11_constexpr : yes (cached) ...
改變 cxxflags 不會清楚上一次 cached 的 feature check 結果, 這是需要刪除 cache 結果

rm -rf bin.v2


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM