# find\_package does not find Boost

**URL:** https://discourse.cmake.org/t/find-package-does-not-find-boost/509
**Category:** Code
**Created:** [January 15, 2020, 9:54pm UTC](https://discourse.cmake.org/t/find-package-does-not-find-boost/509 "2020-01-15T21:54:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![JoeAB](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@JoeAB](https://discourse.cmake.org/u/JoeAB)
#### Post date: [January 15, 2020, 9:54pm UTC](https://discourse.cmake.org/t/find-package-does-not-find-boost/509/1 "2020-01-15T21:54:30Z")

</div>

Our project is building and running on Windows 7 and Ubuntu 16.04. I am now trying to cross compile it under licensed code, copying our project under the _external_ directory. I added BOOST\_ROOT, BOOST\_INCLUDEDIR and Boost\_DIR to the terminal but they get stripped from the environment.  
I have:  
cmake version 3.15.3

Boost is in:  
/usr/local/lib/cmake/Boost-1.71.0/BoostConfig.cmake  
/usr/local/lib/cmake/boost\_XX-1.71.0 folders  
/usr/local/lib/libboost\_XX.so.1.71.0 files

The top of my CMakeLists.txt file, including diagnostics:  
` cmake_minimum_required(VERSION 3.12)`

```
project(MyProject CXX)
message("Running CMakeLists for MyProject!")
# Options
option(GEN_DOCS "Generate documentation" OFF)
option(BUILD_TESTS "Build test executable" ON)
option(INSTALL_LIBRARY "Install the library" OFF)
message("(env)BOOST_ROOT is $ENV{BOOST_ROOT}") #2020-01-14
message("(env)Boost_DIR is $ENV{Boost_DIR}") #2020-01-15
if((${CMAKE_SYSTEM_NAME} STREQUAL "Linux") AND (NOT DEFINED BOOST_ROOT))
    message(STATUS "setting boost_root for Linux")
# SET(BOOST_ROOT "/usr/local/lib/cmake/Boost-1.71.0")
# SET(BOOST_ROOT "/usr/local/lib/cmake")
# SET(BOOST_ROOT "/usr/local/lib")
    SET(BOOST_ROOT "/usr/local")
endif()
message("BOOST_ROOT is " ${BOOST_ROOT}) #2020-01-15
find_package(Boost 1.71.0 REQUIRED COMPONENTS system date_time filesystem)
message("Boost_FOUND is " ${Boost_FOUND}) #2020-01-15
message("Boost_INCLUDE_DIR is " ${Boost_INCLUDE_DIR}) #2020-01-15
message("Boost_DIR is " ${Boost_DIR}) #2020-01-15
message("Boost_CONFIG is " ${Boost_CONFIG}) #2020-01-15
message("Boost_VERSION is " ${Boost_VERSION}) #2020-01-15

```

The output includes:  
| Running CMakeLists for MyProject!  
| (env)BOOST\_ROOT is  
| (env)Boost\_DIR is  
| – setting boost\_root for Linux  
| BOOST\_ROOT is /usr/local  
| CMake Warning at /home/me/dev/source/github/MyProject-build-yocto/—/usr/share/cmake-3.12/Modules/FindBoost.cmake:577 (message):  
| Imported targets and dependency information not available for Boost version  
| (all versions older than 1.33)

and farther down  
| CMake Error at /home/paradigm/dev/source/github/MyProject-build-yocto/—/usr/share/cmake-3.12/Modules/FindBoost.cmake:2048 (message):  
| Unable to find the requested Boost libraries.  
| Unable to find the Boost header files.

and farther down  
| Boost\_FOUND is 0  
| Boost\_INCLUDE\_DIR is Boost\_INCLUDE\_DIR-NOTFOUND  
| Boost\_DIR is Boost\_DIR-NOTFOUND  
| Boost\_CONFIG is  
| Boost\_VERSION is

Is there another way to link to the Boost libraries? Can there be incompatibilities between the _cmake_ program and modules of another version?

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [April 7, 2020, 8:44pm UTC](https://discourse.cmake.org/t/find-package-does-not-find-boost/509/2 "2020-04-07T20:44:00Z")

</div>

You should consider to work with find\_package( **boost\_filesystem** 1.71.0 REQUIRED CONFIG)

and use target\_link\_libraries(… **Boost::filesystem** ) to use imported boost targets.

But it works also with this version:

```cmake
cmake_minimum_required(VERSION 3.16)
project(MyProject CXX)

# Options for boost
option(Boost_DEBUG "Set to ON to enable debug output from FindBoost." OFF)
option(Boost_DETAILED_FAILURE_MSG "Set to ON to get detailed information" OFF)

if(NOT DEFINED BOOST_ROOT)
    set(BOOST_ROOT $ENV{BOOST_ROOT})
endif()

if((${CMAKE_SYSTEM_NAME} STREQUAL "Linux") AND (NOT BOOST_ROOT))
    message(STATUS "setting boost_root for Linux")
    set(BOOST_ROOT "/usr/local")
endif()
message("BOOST_ROOT is ${BOOST_ROOT}") #2020-01-15

find_package(Boost 1.71.0 REQUIRED COMPONENTS system chrono thread filesystem)

message("Boost_FOUND is ${Boost_FOUND}") #2020-01-15
message("Boost_INCLUDE_DIRS is ${Boost_INCLUDE_DIRS}") #2020-01-15
message("Boost_LIBRARIES is ${Boost_LIBRARIES}") #2020-01-15
message("Boost_LIB_DIAGNOSTIC_DEFINITIONS is ${Boost_LIB_DIAGNOSTIC_DEFINITIONS}") #2020-01-15
message("Boost_DIR is ${Boost_DIR}") #2020-01-15
message("Boost_CONFIG is ${Boost_CONFIG}") #2020-01-15
message("Boost_VERSION is ${Boost_VERSION}") #2020-01-15

```

```auto
Claus-MBP:test clausklein$ cmake -G Ninja .
-- The CXX compiler identification is AppleClang 8.0.0.8000042
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
BOOST_ROOT is /usr/local/opt/boost
CMake Warning at /usr/local/opt/boost/lib/cmake/boost_system-1.72.0/libboost_system-variant-shared.cmake:64 (message):
  Target Boost::system already has an imported location
  '/usr/local/Cellar/boost/1.72.0/lib/libboost_system-mt.dylib', which will
  be overwritten with
  '/usr/local/Cellar/boost/1.72.0/lib/libboost_system.dylib'
Call Stack (most recent call first):
  /usr/local/opt/boost/lib/cmake/boost_system-1.72.0/boost_system-config.cmake:57 (include)
  /usr/local/opt/boost/lib/cmake/Boost-1.72.0/BoostConfig.cmake:120 (find_package)
  /usr/local/opt/boost/lib/cmake/Boost-1.72.0/BoostConfig.cmake:185 (boost_find_component)
  /opt/local/share/cmake-3.16/Modules/FindBoost.cmake:443 (find_package)
  CMakeLists.txt:18 (find_package)

CMake Warning at /usr/local/opt/boost/lib/cmake/boost_chrono-1.72.0/libboost_chrono-variant-shared.cmake:64 (message):
  Target Boost::chrono already has an imported location
  '/usr/local/Cellar/boost/1.72.0/lib/libboost_chrono-mt.dylib', which will
  be overwritten with
  '/usr/local/Cellar/boost/1.72.0/lib/libboost_chrono.dylib'
Call Stack (most recent call first):
  /usr/local/opt/boost/lib/cmake/boost_chrono-1.72.0/boost_chrono-config.cmake:57 (include)
  /usr/local/opt/boost/lib/cmake/Boost-1.72.0/BoostConfig.cmake:120 (find_package)
  /usr/local/opt/boost/lib/cmake/Boost-1.72.0/BoostConfig.cmake:185 (boost_find_component)
  /opt/local/share/cmake-3.16/Modules/FindBoost.cmake:443 (find_package)
  CMakeLists.txt:18 (find_package)

CMake Warning at /usr/local/opt/boost/lib/cmake/boost_filesystem-1.72.0/libboost_filesystem-variant-shared.cmake:64 (message):
  Target Boost::filesystem already has an imported location
  '/usr/local/Cellar/boost/1.72.0/lib/libboost_filesystem-mt.dylib', which
  will be overwritten with
  '/usr/local/Cellar/boost/1.72.0/lib/libboost_filesystem.dylib'
Call Stack (most recent call first):
  /usr/local/opt/boost/lib/cmake/boost_filesystem-1.72.0/boost_filesystem-config.cmake:57 (include)
  /usr/local/opt/boost/lib/cmake/Boost-1.72.0/BoostConfig.cmake:120 (find_package)
  /usr/local/opt/boost/lib/cmake/Boost-1.72.0/BoostConfig.cmake:185 (boost_find_component)
  /opt/local/share/cmake-3.16/Modules/FindBoost.cmake:443 (find_package)
  CMakeLists.txt:18 (find_package)

-- Found Boost: /usr/local/opt/boost/lib/cmake/Boost-1.72.0/BoostConfig.cmake (found suitable version "1.72.0", minimum required is "1.71.0") found components: system chrono thread filesystem 
Boost_FOUND is TRUE
Boost_INCLUDE_DIRS is /usr/local/Cellar/boost/1.72.0/include
Boost_LIBRARIES is Boost::system;Boost::chrono;Boost::thread;Boost::filesystem
Boost_LIB_DIAGNOSTIC_DEFINITIONS is 
Boost_DIR is /usr/local/opt/boost/lib/cmake/Boost-1.72.0
Boost_CONFIG is /usr/local/opt/boost/lib/cmake/Boost-1.72.0/BoostConfig.cmake
Boost_VERSION is 1.72.0
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/clausklein/tmp/test
Claus-MBP:test clausklein$ 

```

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [April 7, 2020, 9:09pm UTC](https://discourse.cmake.org/t/find-package-does-not-find-boost/509/3 "2020-04-07T21:09:26Z")

</div>

**cmake -G Ninja -DCMAKE\_PREFIX\_PATH=$BOOST\_ROOT …**

works with

```cmake
find_package(boost_filesystem 1.71.0 REQUIRED CONFIG)

```
