一、安装boost和cmake
brew install boost
- boost库依赖icu4c
- 使用Homebrew安装完boost后其根目录在/usr/local/Cellar/boost,头文件会安装到/usr/local/include,库文件会安装到/usr/local/lib。
二、使用boost
- 新建一个main.cpp文件
#include <iostream>
#include <boost/version.hpp>
using namespace std;
int main(int argc, char const *argv[])
{
cout << BOOST_VERSION << endl;
return 0;
}
- 编译并运行
clang++ main.cpp -o main
./main
三、cmake配置boost
- 安装cmake
brew install cmake
- 创建项目并修改CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(demo VERSION 0.1.0)
set(BOOST_ROOT "/usr/local/Cellar/boost/1.75.0_1")
find_package(Boost 1.75.0 COMPONENTS system)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(demo main.cpp)
target_link_libraries(demo ${Boost_LIBRARIES})
endif(Boost_FOUND)
- 进入build文件夹执行编译
cmake .. && make