linux下編譯boost
下載boot庫
官方下載地址
下載完成會解壓。
編譯
1.進入解壓后的文件夾內
```
cd boost_1_69_0
```
-
執行下面的語句
./bootstrap.sh --with-libraries=all --with-toolset=gcc
- –with-libraries 指定編譯哪些boost庫,all的話就是全部編譯,只想編譯部分庫的話就把庫的名稱寫上,之間用 , 號分隔即可,可指定的庫下面介紹
- –with-toolset 指定編譯時使用哪種編譯器,Linux下使用gcc即可,如果系統中安裝了多個版本的gcc,在這里可以指定gcc的版本,比如–with-toolset=gcc-4.4
命令執行完后看到如下所示即為成功:
```Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2
Detecting Python version... 3.6
Detecting Python root... /opt/anaconda3
Unicode/ICU support for Boost.Regex?... /usr
Generating Boost.Build configuration in project-config.jam...Bootstrapping is done. To build, run:./b2To 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/doc/html/index.html```
-
再執行下面的命令
./b2 toolset=gcc
可指定的庫有:
庫名 說明
- atomic
- chrono
- context
- coroutine
- date_time
- exception
- filesystem
- graph 圖組件和算法
- graph_parallel
- iostreams
- locale
- log
- math
- mpi 用模板實現的元編程框架
- program_options
- python 把C++類和函數映射到Python之中
- random
- regex 正則表達式庫
- serialization
- signals
- system
- test
- thread 可移植的C++多線程庫
- timer
- wave
-
編譯后的庫文件位置
boost_1_69_0/bin.v2/libs/
都在此文件夾內。
安裝到系統
執行下面的命令就可以安裝到系統環境下(本質就是copy)
./b2 install --prefix=/usr
- –prefix=/usr 用來指定boost的安裝目錄,不加此參數的話默認的頭文件在/usr/local/include/boost目錄下,庫文件在/usr/local/lib/目錄下。這里把安裝目錄指定為–prefix=/usr則boost會直接安裝到系統頭文件目錄和庫文件目錄下,可以省略配置環境變量。
如果想讓庫立即生效,需要執行下面的命令
ldconfig