Cmake: How to Connect boost Library

Here is a simple guide on how to connect to boost library in Cmake.

 

How to Connect boost Library to Cmake

Situation 1: Not installed in the default path use:

set(BOOST_ROOT /usr/include/boost)////Set your own path
set(Boost_NO_SYSTEM_PATHS NO)////////Here is the system path for instructions. Generally, the default installation is in /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()

 

 

Situation 2: Install it in the default path and use it directly

 

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()

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *