MacOS中CMakeLists.txt中添加使用boost

只需要在CMakeLists.txt中添加如下的参考即可。

PS:本地的安装版本是1.69.0,换成自己的版本即可。

cmake_minimum_required(VERSION 3.13)
project(test)

set(CMAKE_CXX_STANDARD 14)

add_executable(test main.cpp)

find_package(Boost 1.69.0 COMPONENTS system filesystem REQUIRED)
# 如果需要boost的thread同时添加下面一行
find_package(Boost COMPONENTS thread REQUIRED)
if(NOT Boost_FOUND)
    message(FATAL_ERROR "Could not find boost!")
endif()
include_directories(${Boost_INCLUDE_DIRS})

target_link_libraries(test ${Boost_LIBRARIES} -fsanitize=address)

你可能感兴趣的:(编程开发,C++)