美文网首页
Linux编译和安装boost库

Linux编译和安装boost库

作者: Then丶 | 来源:发表于2020-05-20 11:21 被阅读0次

1. 下载

https://dl.bintray.com/boostorg/release/1.73.0/source/boost_1_73_0.tar.gz
tar zxvf boost(解压)

2.设置编译器和所选库

cd boost
./bootstrap.sh --with-libraries=all --with-toolset=gcc

3.编译boost

./b2 toolset=gcc

4.安装boost

./b2 install --prefix=/usr

--prefix=/usr用来指定boost的安装目录,不加此参数的话默认的头文件在/usr/local/include/boost目录下,库文件在/usr/local/lib/目录下。这里把安装目录指定为--prefix=/usr则boost会直接安装到系统头文件目录和库文件目录下,可以省略配置环境变量。

  • 最后需要注意,如果安装后想马上使用boost库进行编译,还需要执行一下这个命令:
ldconfig(update动态链接库)

5.boost使用测试

#include <boost/thread/thread.hpp> //包含boost头文件
#include <iostream>
#include <cstdlib>
using namespace std;

volatile bool isRuning = true;

void func1()
{
    static int cnt1 = 0;
    while(isRuning)
    {
        cout << "func1:" << cnt1++ << endl;
        sleep(1);
    }
}

void func2()
{
    static int cnt2 = 0;
    while(isRuning)
    {
        cout << "\tfunc2:" << cnt2++ << endl;
        sleep(2);
    }
}

int main()
{
    boost::thread thread1(&func1);
    boost::thread thread2(&func2);

    system("read");
    isRuning = false;

    thread2.join();
    thread1.join();
    cout << "exit" << endl;
    return 0;
}
  • 编译
g++ main.cpp -g -o main -lboost_thread -lpthread
image.png

原文: https://blog.csdn.net/this_capslock/article/details/47170313
原文:https://www.jb51.net/article/150380.htm

相关文章

网友评论

      本文标题:Linux编译和安装boost库

      本文链接:https://www.haomeiwen.com/subject/dfygohtx.html