Install Boost library on windows
Steps
Make sure
gccis the latest, otherwise some unexpected errors might occur.On Windows platform, you can install
msys2, and after update it has all the latestmingw64tool chain for building use, which is convenient.Download tar ball from official website.
Decompress and run
bootstrap.bat, it generatesb2.exeFor linux, run
bootstrap.shinstead ofbootstrap.bat.\bootstrap.batRun
b2.exewith the following options.\b2.exe install \ --build-type=complete \ threading=multi \ link=shared \ address-model=64 \ toolset=gcc \ --prefix="D:\procs\boost_1_79_0"
Note that
gccmust have been set already before this, andprefixis where to copy the headers and libs to.For the day I ran this,
gccI used is frommsys2and its version is12.0, the boost library is1.79.0.After build with out errors, it should say the following
...updated 18043 targets...
Install Boost library on Linux
Steps
Make sure
gccis installedDownload corresponding tar ball from official website.
We need to pay attention, the
gccversion should be somewhat applicable to this boost library version. Otherwise some strange errors come up with compiling.After decompress the tar ball, generate
b2by usingbootstrap.sh./bootstrap.sh --with-libraries=all --with-toolset=gcc
Create a directory for building (not to contaminate current source tree structure)
# Give it a name you want # For example, here abs path is: /home/pyrad/swap/boost_1_69_0/PyradBuild mkdir PyradBuild
Use
b2to compile, specify a build directory in current folder for generating build files (cache, scripts, …)./b2 toolset=gcc --build-dir=/home/pyrad/swap/boost_1_69_0/PyradBuild
After it finishes, the following message will appear,
The Boost C++ Libraries were successfully built! The following directory should be added to compiler include paths: /home/pyrad/procs/boost_1_72_0 The following directory should be added to linker library paths: /home/pyrad/procs/boost_1_72_0/stage/lib
Note
如果在上面的命令中指定了选项:
--build-type=complete, 但没有指定--layout=<versioned|tagged|system>,那么编译的时候会报错,原因是在linux中,如果指定了--build-type=complete,那么就要加上--layout=versioned。但这样做会导致生成的lib目录中的库文件(.so,.a)会带有编译器版本,boost library版本等信息的字符串,如下... libboost_math_c99-gcc9-mt-d-x64-1_69.so libboost_random-gcc9-mt-d-x64-1_69.so libboost_atomic-gcc9-mt-d-x64-1_69.so ...
这样就会导致
cmake的时候抱怨使用find_package不能找到boost library,实际上cmake是试图寻找以下这样的名字... libboost_math_c99.so libboost_random.so libboost_atomic.so ...
在linux中,
--layout这个选项的默认值是system,即产生的库文件名称不带有编译器版本boost库版本等信息(如上)。Install the libraries and header files to a path you specify
./b2 install --prefix=<SOME_USER_PATH>
因为没有指定
--layout=versioned,所以生成的目录结构如下boost_1_69_0/ |---include/ | |---boost/ | |---<all *.hpp headers> | |---<all_header_filer_folders> | |---lib/ |---<all *.so files> |---<all *.a files>