compile boost 1.66.0 from source on ubuntu 16.04


Series

Guide

apt-get

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

compile from source

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.

Author: kezunlin
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source kezunlin !
评论
  TOC