版本 | 颁布日期 | 修订章节 | 作者 |
---|---|---|---|
0.1 | 2017.11.05 | 撰写草稿 | 钟鑫 |
0.2 | 2017.11.06 | 整理编译环境 | 钟鑫 |
boost库简介
百度百科:
https://baike.baidu.com/item/Boost%E5%BA%93/10671694?fr=aladdin
Boost库是为C++语言标准库提供扩展的一些C++程序库的总称,由Boost社区组织开发、维护。Boost库可以与C++标准库完美共同工作,并且为其提供扩展功能。
Boost库是为C++语言标准库提供扩展的一些C++程序库的总称。
boost库下载
最新版本下载下所示
boost库编译
Windows下编译
Visual studio 2017编译
安装Visual studio 2017社区版,打开Visual studio 2017编译工具命令行选项,如下所示。
查看cl命令
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.4.2
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
C:\Users\zx_work\source>cl
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.11.25547 版
版权所有(C) Microsoft Corporation。保留所有权利。
用法: cl [ 选项... ] 文件名... [ /link 链接选项... ]
C:\Users\zx_work\source>
若没有cl命令,需要在VS2017安装文件夹下找到,并将路径加入系统环境变量中。
F:\Visual_studio_2017\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64\cl.exe
进入boost文件夹
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.4.2
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
C:\Users\zx_work\source>F:
F:\Visual_studio_2017>cd ../Development_Tools/boost/ boost_1_60_0
F:\Development_Tools\boost\boost_1_60_0>
运行文件bootstrap.bat
F:\Development_Tools\boost\boost_1_60_0>bootstrap.bat
Building Boost.Build engine
cl: 命令行 warning D9035 :“GZ”选项已否决,并将在将来的版本中移除
cl: 命令行 warning D9036 :使用“RTC1”而不使用“GZ”
cl: 命令行 warning D9002 :忽略未知选项“/MLd”
Bootstrapping is done. To build, run:
.\b2
To adjust configuration, edit 'project-config.jam'.
Further information:
- Command line help:
.\b2 --help
- Getting started guide:
http://boost.org/more/getting_started/windows.html
- Boost.Build documentation:
http://www.boost.org/build/doc/html/index.html
F:\Development_Tools\boost\boost_1_60_0>
根据Visual studio 2017设置文件project-config.jam
F:\Development_Tools\boost\boost_1_60_0>ls
INSTALL b2.exe boost-build.jam boostcpp.jam bootstrap.sh index.html
project-config.jam tools Jamroot bjam.exe boost.css bootstrap.bat doc
libs rst.css LICENSE_1_0.txt boost boost.png
bootstrap.log index.htm more status
project-config.jam文件状态
import option ;
using msvc : 14.1 : "F:\Visual_studio_2017\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64\cl.exe";
option.set keep-going : false ;
设置
设置:
msvc : 14.1
指定cl位置
"F:\Visual_studio_2017\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64\cl.exe"
运行编译选项,根据需要进行裁剪编译
bjam stage --toolset=msvc-14.1 --without-graph --without-graph_parallel --without-python --stagedir="F:\Development_Tools\boost\boost_1_60_0\lib" link=static runtime-link=static threading=multi address-model=64 debug release
说明:
Visual studio 2017的版本号为:msvc-14.1
--toolset:指定编译工具
--without:不编译某项工具
--stagedir:指定编译后的库路径,不加这个描述默认在当前目录的stage\lib文件里面
开始编译boost库
F:\Development_Tools\boost\boost_1_60_0>bjam stage --toolset=msvc-14.1 --without-graph --without-graph_parallel --without-python --stagedir="F:\Development_Tools\boost\boost_1_60_0\lib" link=static runtime-link=static threading=multi address-model=64 debug release
Performing configuration checks
- 32-bit : no
- 64-bit : yes
- arm : no
- mips1 : no
- power : no
- sparc : no
- x86 : yes
- symlinks supported : no
- junctions supported : yes
- hardlinks supported : yes
编译完成
Unknown compiler version - please run the configure tests and report the results
compile-c-c++ bin.v2\libs\wave\build\msvc-14.1\release\link-static\runtime-link-static\threading-multi\cpplexer\re2clex\cpp_re.obj
cpp_re.cpp
Unknown compiler version - please run the configure tests and report the results
msvc.archive bin.v2\libs\wave\build\msvc-14.1\release\link-static\runtime-link-static\threading-multi\libboost_wave-vc141-mt-s-1_60.lib
common.copy F:\Development_Tools\boost\boost_1_60_0\lib\lib\libboost_wave-vc141-mt-s-1_60.lib
bin.v2\libs\wave\build\msvc-14.1\release\link-static\runtime-link-static\threading-multi\libboost_wave-vc141-mt-s-1_60.lib
已复制 1 个文件。
...updated 1094 targets...
F:\Development_Tools\boost\boost_1_60_0>
编译出来的boost库文件如下所示。
编译完成后就可以在工程文件直接引用boost库。
Linux下编译
进入boost文件夹,运行文件./bootstrap.sh
~/Tools/boost_1_60_0$ ./bootstrap.sh
Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2
Detecting Python version... 2.7
Detecting Python root... /usr
Unicode/ICU support for Boost.Regex?... not found.
Generating Boost.Build configuration in project-config.jam...
Bootstrapping is done. To build, run:
./b2
To 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
ghost@ghost-machine:~/Tools/boost_1_60_0$
开始编译boost库
~/Tools/boost_1_60_0$./bjam stage --without-graph --without-graph_parallel --without-python
aph_parallel --without-python
Performing configuration checks
- 32-bit : no
- 64-bit : yes
- arm : no
- mips1 : no
- power : no
- sparc : no
- x86 : yes
- symlinks supported : yes
- lockfree boost::atomic_flag : yes
- zlib : yes
- iconv (libc) : yes
- icu : no
- icu (lib64) : no
- compiler-supports-visibility : yes
- compiler-supports-ssse3 : yes
- has_icu builds : no
- compiler-supports-avx2 : yes
- gcc visibility : yes
- long double support : yes
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
- zlib
编译完成
gcc.compile.c++ bin.v2/libs/wave/build/gcc-5.4.0/release/link-static/threading-multi/cpplexer/re2clex/cpp_re.o
gcc.archive bin.v2/libs/wave/build/gcc-5.4.0/release/link-static/threading-multi/libboost_wave.a
common.copy stage/lib/libboost_wave.a
...failed updating 2 targets...
...skipped 6 targets...
...updated 1036 targets...
~/Tools/boost_1_60_0$
编译完成的boost库在stage文件夹下
~/Tools/boost_1_60_0/stage/lib$ ls
libboost_atomic.a libboost_math_tr1l.so
libboost_atomic.so libboost_math_tr1l.so.1.60.0
libboost_atomic.so.1.60.0 libboost_math_tr1.so
libboost_chrono.a libboost_math_tr1.so.1.60.0
libboost_chrono.so libboost_prg_exec_monitor.a
libboost_chrono.so.1.60.0 libboost_prg_exec_monitor.so
libboost_container.a libboost_prg_exec_monitor.so.1.60.0
libboost_container.so libboost_program_options.a
libboost_container.so.1.60.0 libboost_program_options.so
libboost_context.a libboost_program_options.so.1.60.0
libboost_context.so libboost_random.a
libboost_context.so.1.60.0 libboost_random.so
libboost_coroutine.a libboost_random.so.1.60.0
libboost_coroutine.so libboost_regex.a
libboost_coroutine.so.1.60.0 libboost_regex.so
libboost_date_time.a libboost_regex.so.1.60.0
libboost_date_time.so libboost_serialization.a
libboost_date_time.so.1.60.0 libboost_serialization.so
libboost_exception.a libboost_serialization.so.1.60.0
libboost_filesystem.a libboost_signals.a
libboost_filesystem.so libboost_signals.so
libboost_filesystem.so.1.60.0 libboost_signals.so.1.60.0
libboost_locale.a libboost_system.a
libboost_locale.so libboost_system.so
libboost_locale.so.1.60.0 libboost_system.so.1.60.0
libboost_log.a libboost_test_exec_monitor.a
libboost_log_setup.a libboost_thread.a
libboost_log_setup.so libboost_thread.so
libboost_log_setup.so.1.60.0 libboost_thread.so.1.60.0
libboost_log.so libboost_timer.a
libboost_log.so.1.60.0 libboost_timer.so
libboost_math_c99.a libboost_timer.so.1.60.0
libboost_math_c99f.a libboost_type_erasure.a
libboost_math_c99f.so libboost_type_erasure.so
libboost_math_c99f.so.1.60.0 libboost_type_erasure.so.1.60.0
libboost_math_c99l.a libboost_unit_test_framework.a
libboost_math_c99l.so libboost_unit_test_framework.so
libboost_math_c99l.so.1.60.0 libboost_unit_test_framework.so.1.60.0
libboost_math_c99.so libboost_wave.a
libboost_math_c99.so.1.60.0 libboost_wave.so
libboost_math_tr1.a libboost_wave.so.1.60.0
libboost_math_tr1f.a libboost_wserialization.a
libboost_math_tr1f.so libboost_wserialization.so
libboost_math_tr1f.so.1.60.0 libboost_wserialization.so.1.60.0
libboost_math_tr1l.a
~/Tools/boost_1_60_0/stage/lib$
将boost库安装至系统环境中
编辑文本文件/etc/profile
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/home/ghost/Tools/boost_1_60_0
export LIBRARY_PATH=$LIBRARY_PATH:/home/ghost/Tools/boost_1_60_0/stage/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/ghost/Tools/boost_1_60_0/stage/lib
boost库头文件
需要引用的boost库头文件位置:./boost/
/boost_1_60_0 $ ls
INSTALL bootstrap.sh*
Jamroot doc/
LICENSE_1_0.txt index.htm
b2.exe* index.html
bin.v2/ lib/
bjam.exe* libs/
boost/ more/
boost-build.jam project-config.jam
boost.css rst.css
boost.png stage/
boostcpp.jam status/
bootstrap.bat tools/
bootstrap.log