码迷,mamicode.com
首页 > 其他好文 > 详细

centos(x86 64位系统)使用boost

时间:2015-07-23 23:34:07      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

1. 安装gcc,g++,make等开发环境

技术分享
yum groupinstall "Development Tools"
View Code

 

 2. 安装boost

技术分享
yum install boost boost-devel boost-doc
View Code
备注:默认的安装路径在/usr/lib64目录下

 

3. 例子 

技术分享
#include <boost/thread.hpp>  
#include <iostream>  
  
void task1() {   
    // do stuff  
    std::cout << "This is task1!" << std::endl;  
}  
  
void task2() {   
    // do stuff  
    std::cout << "This is task2!" << std::endl;  
}  
  
int main (int argc, char ** argv) {  
    using namespace boost;   
    thread thread_1 = thread(task1);  
    thread thread_2 = thread(task2);  
  
    // do other stuff  
    thread_2.join();  
    thread_1.join();  
    return 0;  
} 
View Code

 

4. 编译

技术分享
g++ -I./inlcude -L./usr/lib64  asio_thread.cpp -lboost_thread-mt  -o example
View Code

 

5.运行: 

This is task2!
This is task1!

 

 

 

centos(x86 64位系统)使用boost

标签:

原文地址:http://www.cnblogs.com/super-d2/p/4671887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!