up -ubuntu18.04安装boost

# system: ubuntu 18.04
# version: boost 1.78.0

# 安装依赖
> sudo apt-get -y install python-dev libxml2-dev libxslt-dev libbz2-dev
# 下载boost1.78.0
# wget https://raw.githubusercontent.com/lylei9/boost_1_57_0/master/boost_1_57_0.tar.gz
> wget https://sourceforge.net/projects/boost/files/boost/1.78.0/boost_1_78_0.tar.gz/download
# 下载可能会比较慢,自己想办法下载
> tar zxvf boost_1_78_0.tar.gz
> cd boost_1_78_0
> ./bootstrap.sh --prefix=/usr/local/boost
> ./b2
> sudo ./b2 install
> sudo vim /etc/profile
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/boost/include
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/boost/lib
> source /etc/profile
# 添加动态库
> sudo vim /etc/ld.so.conf
/usr/local/boost/lib
> sudo ldconfig
output
> g++ test_boost.cc
> ./a.out
105700
1_57
linux
GNU C++ version 7.5.0
GNU libstdc++ version 20191114
#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 << "func2:" << 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++ test_boost_thread.cc -o test_boost_thread -lboost_thread -lpthread -lboost_system
# https://www.reddit.com/r/cpp_questions/comments/cc0v4s/undefined_reference_to_symbol_from_boost_library/
error: sh: 1: read: arg count
# https://unix.stackexchange.com/questions/581409/error-sh-1-read-arg-count
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值