Ubuntu下使用boost例子

http://blog.csdn.net/dotphoenix/article/details/8459277

1. 安装boost库 

sudo apt-get install libboost-all-dev
或者使用源代码编译:
sudo apt-get install python2.6-dev

sudo apt-get install libicu-dev

sudo apt-get install libbz2-dev

然后手动下载
http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz
解压后安装.(执行./configure make make install三个命令)
然后访问下面地址下载
http://sourceforge.net/projects/libpng/files/zlib/1.2.5/zlib-1.2.5.tar.gz/download
同样进行解压安装
ldconfig
sudo apt-get update
wget -c 'http://sourceforge.net/projects/boost/files/boost/1.50.0/boost_1_50_0.tar.bz2/download'
tar xf download
cd boost_1_50_0
首先要编译生成boost安装工具bjam
进入boost目录执行:
./bootstrap.sh
然后执行刚生成的
./bjam -s HAVE_ICU=1
编译开始,大约半小时,全部编译结束。
./bjam install --prefix=/usr
将当前目录下编译好的头文件安装到相应位置:在/usr/include下有头文件夹boost,在/usr/lib下有boost的库
2. 例子
  1. #include <boost/thread.hpp>  
  2. #include <iostream>  
  3.   
  4. void task1() {   
  5.     // do stuff  
  6.     std::cout << "This is task1!" << std::endl;  
  7. }  
  8.   
  9. void task2() {   
  10.     // do stuff  
  11.     std::cout << "This is task2!" << std::endl;  
  12. }  
  13.   
  14. int main (int argc, char ** argv) {  
  15.     using namespace boost;   
  16.     thread thread_1 = thread(task1);  
  17.     thread thread_2 = thread(task2);  
  18.   
  19.     // do other stuff  
  20.     thread_2.join();  
  21.     thread_1.join();  
  22.     return 0;  
  23. }  
3. Makefile
g++ -I./inlcude -L./lib example.cpp -lboost_thread -o example
4.运行结果
This is task2!
This is task1!
原文地址:https://www.cnblogs.com/dreamforever/p/3712301.html