Boost Arm 交叉編譯
1. 源碼下載
下載地址:https://sourceforge.net/projects/boost/files/boost/
這里下載 1.74.0 版本
然后解壓。
2. 配置
有些庫我們是不需要的,所以就不需要編譯,可以通過 -show-libraries
查看庫列表
vincent@msi-creator-15:~/Temp/arm/boost_1_74_0$
---? ./bootstrap.sh --show-libraries
Building Boost.Build engine with toolset gcc... tools/build/src/engine/b2The following Boost libraries have portions that require a separate build
and installation step. Any library not listed here can be used by including
the headers only.The Boost libraries requiring separate building and installation are:- atomic- chrono- container- context- contract- coroutine- date_time- exception- fiber- filesystem- graph- graph_parallel- headers- iostreams- locale- log- math- mpi- nowide- program_options- python- random- regex- serialization- stacktrace- system- test- thread- timer- type_erasure- wave
通過 -without-libraries=, , ,
逗號隔開去掉不想編譯的庫,并指定安裝位置:
./bootstrap.sh --without-libraries=atomic,chrono --prifix=./install
這里還是全部編譯了,所以直接執行下面命令
./bootstrap.sh --prefix=./install
執行后結果
vincent@msi-creator-15:~/Temp/arm/boost_1_74_0$
---? ./bootstrap.sh --prefix=./install
Building Boost.Build engine with toolset gcc... tools/build/src/engine/b2
Detecting Python version... 3.9
Detecting Python root... /home/vincent/anaconda3
Unicode/ICU support for Boost.Regex?... /usr
Generating Boost.Build configuration in project-config.jam for gcc...Bootstrapping is done. To build, run:./b2To generate header files, run:./b2 headersTo adjust configuration, edit 'project-config.jam'.
Further information:- Command line help:./b2 --help- Getting started guide: http://www.boost.org/more/getting_started/unix-variants.html- Boost.Build documentation:http://www.boost.org/build/
3. 修改配置
上一步將會生成主要的2個文件:
- b2
- project-config.jam
3.1 修改編譯器
打開 project-config.jam 文件修改內的編譯器
將此句修改為交叉編譯器路徑
using gcc : : /xxx/gcc-arm-11.2-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc ;
這里語法很苛刻,需要注意下面圖內標注的地方都是需要有空格的。
3.2 修改安裝目錄
這里同樣要注意空格。
3.3 其他配置
-
選項
-
build-type
構建類型,默認是 minimal ,此外還有complete
選項。minimal 在Linux下只編譯 release版本的多線程靜態庫和動態庫。而 complete 在 unix/linux 下將會編譯多個版本,即 debug 或 release,多線程或單線程,靜態庫或動態庫。一般不建議全部編譯,費時還費空間,提倡按需編譯。 -
build-dir
構建目錄,不指定將會在源碼目錄構建。 -
layout
確定是否選擇庫名和頭文件位置,以便Boost的多個版本或多個編譯器可以在同一個系統上使用。有以下3個選項配置。versioned
二進制文件的名稱包含版本號、編譯器名稱和版本以及編碼的構建屬性。頭文件將會安裝在 HDRDIR 的子目錄中,其名稱包含boost的版本號。tagged
二進制文件的名稱包含編碼的構建屬性,但不包含編譯器名稱和版本或boost版本。如果使用同一個編譯器構建多個boost,推薦使用。system
二進制文件名稱不包含boost版本號或編譯器的名稱和版本號,boost頭文件直接安裝到 HDRDIR 目錄中。
windows 默認是選擇
versioned
,unix默認選擇system
。當build-type
為 complete時,variant=debug,release屬性時,必須要確保 layout=versioned或tagged。 -
without
設置排除編譯的庫。
-
-
屬性
-
variant
= debug|release,編譯庫的模式,支持同時編譯。 -
link
= static|shared,編譯靜態庫還是動態庫。 -
runtime-link
=static|shared,指創建的庫是靜態鏈接還是動態鏈接到C運行庫(或C++標準庫),這個屬性需要依據 link 的類型,不同的編譯器允許的鏈接策略不一樣,比如在 GCC 下,在生成動態庫(-link=shared)時,就不允許進行靜態鏈接到C運行庫(或C++標準庫)這里重點強調一下,當link為static時,runtime-link可以是shared,boost本身依賴的C/C++底層庫就是動態鏈接的,但是對于boost而言是靜態鏈接,好比A程序依賴boost,A與boost是靜態鏈接,但是boost與C/C++運行庫是動態的。
-
threading
= single|multi,創建多線程還是單線程的版本。
屬性是支持同時設置的,比如:
variant=debug,release # 或 variant=debug variant=release
-
配置的命令示例如下:
./b2 --layout=tagged-sHAVE_ICU=1variant=debug,release link=static runtime-link=shared threading=multi
sHAVE_ICU=1
代表支持 Unicode/ICU。
4. 編譯
執行下面命令開始編譯
./b2
編譯成功后如下提示:
5. 安裝
編程完成的靜態或動態庫文件就在stage目錄中。
vincent@msi-creator-15:~/Temp/arm/boost_1_74_0$
---? tree -L 1 stage
stage
└── lib
但是缺少頭文件,執行下面的命令進行安裝,頭文件和庫將會拷貝到源碼目錄下的 install 目錄中。
./b2 install