1、首先去www.boost.org网站 下载boost库压缩文件,比如boost_1_64_0.tar.gz或者在SourceForge用 wget 直接下载,网址:
https://sourceforge.net/projects/boost/files/boost/1.64.0/boost_1_64_0.7z
https://sourceforge.net/projects/boost/files/boost/1.64.0/boost_1_64_0.tar.gz
2、安装boost依赖包:
yum -y install gcc gcc-c++ python python-devel libicu libicu-devel zlib zlib-devel bzip2 bzip2-devel
若缺少依赖包会提示以下信息:
提示信息【Unicode/ICU support for Boost.Regex?... not found.】,依赖包【 libicu libicu-devel 】
提示信息【error: no command provided, default command 'g++' not found】,依赖包【 gcc-c++ 】
提示信息【- zlib : no】,依赖包【 zlib zlib-devel 】
提示信息【- bzip2 : no】,依赖包【 bzip2 bzip2-devel 】
3、执行命令:tar xvfz boost_1_64_0.tar.gz,解压boost库;
4、进入解压出的boost目录,执行./bootstrap.sh编译boost库;
注意:如果编译失败了,建议" rm -rf boost_1_64_0"之后,重新解压,重新编译。
5、执行./b2 install安装;
6、测试验证:
#include <string>
#include <iostream>
#include <boost/version.hpp> //包含Boost头文件
#include <boost/config.hpp> //包含Boost头文件
using namespace std;
int main()
{
cout << BOOST_VERSION << endl; //Boost版本号
cout << BOOST_LIB_VERSION << endl; //Boost版本号
cout << BOOST_PLATFORM << endl; //操作系统
cout << BOOST_COMPILER << endl; //编译器
cout << BOOST_STDLIB << endl; //标准库
}
然后使用g++编译:
g++ -o boost_test.out boost_test.cpp -I.
运行:
./boost_test.out
结果:
106800
1_68
linux
GNU C++ version 4.8.5
GNU libstdc++ version 20150623
至此boost安装完成。