Ubuntu 16.04源码编译boost库 编写CMakeLists.txt | compile boost 1.66.0 from source on ubuntu 16.04

本文首发于个人博客https://kezunlin.me/post/d5d4a460/,欢迎阅读!

compile boost 1.66.0 from source on ubuntu 16.04

Guide

apt-get

    # 1.58 for ubuntu 16.04
    sudo apt-get install libboost-all-dev

compile from source

    sudo apt-get -y purge libboost-all-dev
    wget https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz
    tar xzvf boost_1_66_0.tar.gz
    cd boost_1_66_0/
    sudo apt-get update
    sudo apt-get install build-essential g   python-dev autotools-dev libicu-dev build-essential libbz2-dev
    ./bootstrap.sh --prefix=/usr/local/
    ./b2 --help
    ./b2 -j8 variant=release link=shared threading=multi runtime-link=shared
    sudo ./b2 -j8 install 

thread example

thread_demo.cpp

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

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

boost::mutex io_mutex;

void count(int id)
{
    for (int i = 0; i < 10; i  )
    {
        boost::mutex::scoped_lock lock(io_mutex);
        std::cout << id << ":" << i << std::endl;
    }
}

int main(int argc, char* argv[])
{
    boost::thread thrd1(boost::bind(&count, 1));
    boost::thread thrd2(boost::bind(&count, 2));
    thrd1.join();
    thrd2.join();
    return 0;
}

CMakeLists.txt

cmake_minimum_required (VERSION 2.6)

project (thread_main)
enable_language(C)
enable_language(CXX)

set(Boost_USE_RELEASE_LIBS ON)
#set(Boost_USE_STATIC_LIBS OFF) # use .a or .so file
set(Boost_USE_MULTITHREAD ON)

# Find Boost package 1.5.8 or 1.6.6
find_package(Boost 1.5.8 REQUIRED COMPONENTS serialization date_time system filesystem thread timer)
include_directories(${Boost_INCLUDE_DIRS})

add_executable (thread_main
    thread_main.cpp
)

target_link_libraries (thread_main 
    ${Boost_LIBRARIES}
)

thread pool

see thread pool with boost

Reference

History

  • 20180131: created.

Copyright

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值