Installation and testing of boost library

1. Introduction to boost library

  Boost is a general term for some C++ libraries that provide extensions to the C++ language standard library. The Boost library is a portable C++ library that provides source code. As a backup of the standard library, it is one of the development engines of the C++ standardization process. It is a general term for some C++ libraries that provide extensions to the C++ language standard library.
  The Boost library was initiated by members of the C++ Standards Committee Library Working Group, and some of its content is expected to become the next generation of C++ standard library content. It has a great influence in the C++ community and is an out-and-out "quasi" standard library.
  Boost has nothing to do with the writing platform because of its emphasis on cross-platform and standard C++. But there are also many experimental things in Boost, which need to be used with caution in actual development.

Second, the installation and installation of the boost library

   1. Download

Official website address: Boost C++ Libraries

           2. Installation

Decompress the downloaded file, open the terminal, and enter 2. Installation and installation of the boost library

./bootstrap.sh

3. Test

#include <iostream>
#include <boost/thread/thread.hpp> 
#include <boost/thread/mutex.hpp> 
 
boost::mutex mutex;
 
void print_block(int n, char c)
{
 
    mutex.lock();
    for (int i = 0; i < n; ++i)
    {
        std::cout << c;
    }
    std::cout << '\n';
    mutex.unlock();
}
 
int main(int argc, char* argv[])
{
    boost::thread thread1(&print_block, 300, '*');
    boost::thread thread2(&print_block, 300, '$');
 
    thread1.join();
    thread2.join();
 
    return 0;
}


# cmake needs this line
cmake_minimum_required(VERSION 2.8)          # 声明要求的cmake最低版本
project(boost_test)                  # 声明一个cmake工程    VERSION 0.1.0 添加的版本号
add_executable(boost_test boost_test.cpp)
# 1. boost
find_package(Boost REQUIRED COMPONENTS system thread)#for boost
add_definitions(${Boost_INCLUDE_DIRS})
include_directories(boost_test ${Boost_INCLUDE_DIRS}})
target_link_libraries(boost_test  ${Boost_LIBRARIES})











Guess you like

Origin blog.csdn.net/m0_48919875/article/details/126134072