阿里云服务器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

【阿里云服务器centos8系统安装和使用boost】4、安装boost.build
cd /boost/tools/build sudo ./bootstrap.sh sudo ./b2 install --prefix=/usr/local/include/boost ldconfig

三、验证
1、程序thread.cpp
#include #include 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

    推荐阅读