c++简单使用boost

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/luoyexuge/article/details/80316356

准备学习下boost,下午刚刚好把环境装了下,下面通过用thread为例子:

 

boost简单的安装:

wget    https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.tar.gz
cd  boost_1_67_0
sh bootstrap.sh
./b2

cmake安装:

sudo tar -zxvf cmake-3.11.tar.gz 

cd   cmake-3.11

sudo ./bootstrap

sudo make

sudo make install

 

项目tree:

.

├── build

├── CMakeLists.txt

└── main.cpp

 

CMakeLists.txt:

PROJECT(HELLO) 

include_directories(/home/meixu.zmx/boost_1_67_0)

link_directories(/home/meixu.zmx/boost_1_67_0/stage/lib)

add_executable(llll main.cpp)

target_link_libraries(llll libboost_thread.so libboost_system.so)

main.cpp

#include <boost/thread/thread.hpp>  
#include <iostream>
using namespace  std;

void task1()

{  

     for(int i=0;i<10;i++){



    std::cout << "This is task1: "<<i << std::endl; 

}

}

void  task2(){

for(int i=0;i<10;i++){

    std::cout << "This is task2: "<<i << std::endl; 

}

}



int main(){

  cout<<"hellow world"<<endl;

  boost::thread thread_1 = boost::thread(task1);  

  boost::thread thread_2 = boost::thread(task2);  

  thread_2.join();  

  thread_1.join();

  return 0;



}






编译项目:

cmake .. && make && ./llll

hellow world

This is task2: This is task1: 0

This is task2: 1

This is task2: 2

This is task2: 3

This is task2: 4

This is task2: 5

This is task2: 6

This is task2: 7

This is task2: 8

This is task2: 9

0

This is task1: 1

This is task1: 2

This is task1: 3

This is task1: 4

This is task1: 5

This is task1: 6

This is task1: 7

This is task1: 8

This is task1: 9





​

 

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页