Two ways, using system default install path, usually /usr/lib/x86_64-linux-gnu/:
find_package(Boost REQUIRED regex date_time system filesystem thread graph) include_directories(${BOOST_INCLUDE_DIRS}) message("boost lib: ${Boost_LIBRARIES}") message("boost inc:${Boost_INCLUDE_DIR}") add_executable(use_boost use_boost.cpp) target_link_libraries(use_boost ${Boost_LIBRARIES} )
If you install Boost in a local directory or choose local install instead of system install, you can do it by this:
set( BOOST_ROOT "/home/xy/boost_install/lib/" CACHE PATH "Boost library path" ) set( Boost_NO_SYSTEM_PATHS on CACHE BOOL "Do not search system for Boost" ) find_package(Boost REQUIRED regex date_time system filesystem thread graph) include_directories(${BOOST_INCLUDE_DIRS}) message("boost lib: ${Boost_LIBRARIES}, inc:${Boost_INCLUDE_DIR}") add_executable(use_boost use_boost.cpp) target_link_libraries(use_boost ${Boost_LIBRARIES} )
Note the above dir /home/xy/boost_install/lib/ is where I install Boost:
xy@xy:~/boost_install/lib$ ll -th total 16K drwxrwxr-x 2 xy xy 4.0K May 28 19:23 lib/ drwxrwxr-x 3 xy xy 4.0K May 28 19:22 include/ xy@xy:~/boost_install/lib$ ll -th lib/ total 57M drwxrwxr-x 2 xy xy 4.0K May 28 19:23 ./ -rw-rw-r-- 1 xy xy 2.3M May 28 19:23 libboost_test_exec_monitor.a -rw-rw-r-- 1 xy xy 2.2M May 28 19:23 libboost_unit_test_framework.a ....... xy@xy:~/boost_install/lib$ ll -th include/ total 20K drwxrwxr-x 110 xy xy 12K May 28 19:22 boost/
If you are interested in how to use a local installed Boost, you can see this question How can I get CMake to find my alternative Boost installation?.