boost

boost文件结构

编译后得到的文件分布一般是这种情况

# kun @ Mac in ~/libs/boost_1_79_0 [20:23:14]
$ ll
total 808
drwxr-xr-x@  26 kun  staff   832B  1 17  2023 .
drwxr-xr-x    6 kun  staff   192B  5 12  2022 ..
-rw-r--r--@   1 kun  staff   6.0K  1 17  2023 .DS_Store
-rw-r--r--@   1 kun  staff   291B  4  7  2022 INSTALL
-rw-r--r--@   1 kun  staff    12K  4  7  2022 Jamroot
-rw-r--r--@   1 kun  staff   1.3K  4  7  2022 LICENSE_1_0.txt
-rw-r--r--@   1 kun  staff   542B  4  7  2022 README.md
-rwxr-xr-x    1 kun  staff   299K  5 12  2022 b2
drwxr-xr-x    8 kun  staff   256B  5 12  2022 bin.v2
drwxr-xr-x@ 291 kun  staff   9.1K  1 17  2023 boost
-rw-r--r--@   1 kun  staff   850B  4  7  2022 boost-build.jam
-rw-r--r--@   1 kun  staff   989B  4  7  2022 boost.css
-rw-r--r--@   1 kun  staff   6.2K  4  7  2022 boost.png
-rw-r--r--@   1 kun  staff    20K  4  7  2022 boostcpp.jam
-rw-r--r--@   1 kun  staff   2.4K  4  7  2022 bootstrap.bat
-rwxr-xr-x@   1 kun  staff    11K  4  7  2022 bootstrap.sh
drwxr-xr-x@  13 kun  staff   416B  4  7  2022 doc
-rw-r--r--@   1 kun  staff   769B  4  7  2022 index.htm
-rw-r--r--@   1 kun  staff   5.3K  4  7  2022 index.html
drwxr-xr-x@ 151 kun  staff   4.7K  1 17  2023 libs
drwxr-xr-x@   8 kun  staff   256B  4  7  2022 more
-rw-r--r--    1 kun  staff   987B  5 12  2022 project-config.jam
-rw-r--r--@   1 kun  staff   2.5K  4  7  2022 rst.css
drwxr-xr-x    3 kun  staff    96B  5 12  2022 stage
drwxr-xr-x@   8 kun  staff   256B  4  7  2022 status
drwxr-xr-x@  17 kun  staff   544B  4  7  2022 tools

然后可以执行b2 install
比如我会安装到自己指定的路径中

./b2 install --prefix=/Users/kun/usr/boost_1_83_0

boost::log cmake 例子

文件结构

$ tree
.
├── CMakeLists.txt
└── src
    └── main.cpp

CmakeLists.txt

cmake_minimum_required(VERSION 3.14)
project(main LANGUAGES CXX)

##########################
#add include path
##########################
set(CMAKE_INCLUDE_CURRENT_DIR ON)

##########################
#set c11 -std=c11 c++11
##########################
set(C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_VERBOSE_MAKEFILE ON)

find_package(Boost REQUIRED COMPONENTS log system)

set(PROJECT_SOURCES
    src/main.cpp
)

add_executable(main ${PROJECT_SOURCES})
target_link_libraries(main Boost::log Boost::system)

main.cpp

#include <iostream>

#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/trivial.hpp>

using namespace std;
namespace logging = boost::log;

int main(int argc, char* argv[]){
    logging::add_file_log(logging::keywords::file_name = "/home/kun/Desktop/boost.log",
                          logging::keywords::rotation_size = 10 * 1024 * 1024,
                          logging::keywords::auto_flush = true);
    logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::info);
    BOOST_LOG_TRIVIAL(info) << "This is an info message";
    BOOST_LOG_TRIVIAL(error) << "This is an error message";
    return 0;
}

build

cmake -Bbuild -DBOOST_ROOT=/home/kun/usr/boost_1_82_0

cmake和boost相关的几个变量:

Boost_INCLUDE_DIRS
Boost_LIBRARY_DIRS
Boost_LIBRARIES
BOOST_ROOT
BOOSTROOT

具体可参考 https://cmake.org/cmake/help/latest/module/FindBoost.html#findboost

posted @ 2023-09-13 20:26  feipeng8848  阅读(21)  评论(0编辑  收藏  举报