1、下载boost库(git repo和下面的不一样)
2、解压
3、在解压后的目录执行bootstrap.sh,生成配置文件
4、执行bjam(b2) ,bjam填上自己的参数,我的参数如下
./bjam install threading=multi release --without-fiber --without-graph --without-graph_parallel --without-math --without-mpi --without-program_options --without-python --without-test --without-wave --prefix=/home/burning/boost
5、等30分钟后,编译完成,可以在/home/burning/目录下面看到生成的头文件和库文件
6、配置ld.so.conf, 在/etc/ld.so.cond.d/文件夹下面新建一个文件boost.conf,然后把"/home/burning/boost/lib/"添加到boost.conf中,sudo ldconfig。这一步配置为了防止运行时找不到动态库
7、写个程序测试一下
#include "boost/thread/thread.hpp"
#include <iostream>
void hello()
{
std::cout <<
"Hello world, I''m a thread!"
<< std::endl;
}
int main(int argc, char* argv[])
{
boost::thread thrd(&hello);
thrd.join();
return 0;
}
g++ -o thread -g thread.cpp -I /home/burning/boost/include/boost -L /home/burning/boost/lib -lboost_system -lboost_thread
然后就生成可执行程序,运行结果如下
➜ workspace ./thread
Hello world, I''m a thread!
➜ workspace