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

阿里云服务器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
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

加班猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值