关于centos8:阿里云服务器centos8系统安装和使用boost

43次阅读

共计 1157 个字符,预计需要花费 3 分钟才能阅读完成。

阿里云服务器 centos8 零碎装置和应用 boost

一. 间接用 yum 装置

yum install boost
yum install boost-devel
yum install boost-doc

二. 安装包装置

1、去官网 boost 下载你想要的安装包
2、装置 boost 依赖包:yum -y install gcc gcc-c++ python python-devel libicu libicu-devel zlib zlib-devel bzip2 bzip2-devel
3、拷贝到零碎

tar -zxvf boost_1_78_0.tar.gz
cd boost_1_78_0
# 默认装置
sudo ./bootstrap.sh 
# 也能够指定装置目录,例如
sudo ./bootstrap.sh --prefix=/usr/local/include/boost
# 装置 boost
sudo ./b2 install

4、装置 boost.build

cd /boost/tools/build
sudo ./bootstrap.sh
sudo ./b2 install --prefix=/usr/local/include/boost
ldconfig

三、验证

1、程序 thread.cpp

#include <boost/thread.hpp> 
#include <iostream> 

void wait(int seconds) 
{boost::this_thread::sleep(boost::posix_time::seconds(seconds)); 
} 

boost::mutex mutex; 

void thread() 
{for (int i = 0; i < 5; ++i) 
    {wait(1); 
        mutex.lock(); 
        std::cout << "Thread" << boost::this_thread::get_id() << ":" << i << std::endl; 
        mutex.unlock();} 
} 

int main() 
{boost::thread t1(thread); 
    boost::thread t2(thread); 
    t1.join(); 
    t2.join();} 

2、编译执行

[root@hackett boost]# g++ thread.cpp -o thread -lboost_thread
[root@hackett boost]# ./thread
Thread 7f520774c700: 0
Thread 7f5206f4b700: 0
Thread 7f5206f4b700: 1
Thread 7f520774c700: 1
Thread 7f5206f4b700: 2
Thread 7f520774c700: 2
Thread 7f520774c700: 3
Thread 7f5206f4b700: 3
Thread 7f5206f4b700: 4
Thread 7f520774c700: 4

正文完
 0