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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
2018-09-13 c# 表达式树快速入门