Cmake链接boost库

没有安装在默认路径下使用:

 

set(BOOST_ROOT /usr/include/boost)////设置自己的路径
set(Boost_NO_SYSTEM_PATHS NO)////////这里是说明用系统路径  一般默认使用 默认安装在/usr/include/boost
find_package(Boost COMPONENTS regex system REQUIRED)

if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
MESSAGE( STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}.")
MESSAGE( STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}.")
MESSAGE( STATUS "Boost_LIB_VERSION = ${Boost_LIB_VERSION}.")
add_executable(main main.cpp)
target_link_libraries (main ${Boost_LIBRARIES})
endif()

 

 

安装在默认路径 直接使用好了

 

find_package(Boost COMPONENTS regex system REQUIRED)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
MESSAGE( STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}.")
MESSAGE( STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}.")
MESSAGE( STATUS "Boost_LIB_VERSION = ${Boost_LIB_VERSION}.")
add_executable(main main.cpp)
target_link_libraries (main ${Boost_LIBRARIES})
endif()

posted on 2022-02-22 11:38  D社长  阅读(1088)  评论(0)    收藏  举报