# FindBoost ignores all hints and won't find the right installation

**URL:** https://discourse.cmake.org/t/findboost-ignores-all-hints-and-wont-find-the-right-installation/3883
**Category:** Usage
**Tags:** os:linux
**Created:** [August 5, 2021, 3:55pm UTC](https://discourse.cmake.org/t/findboost-ignores-all-hints-and-wont-find-the-right-installation/3883 "2021-08-05T15:55:37Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![jsuthe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jsuthe/32/1656_2.png) [@jsuthe](https://discourse.cmake.org/u/jsuthe)
#### Post date: [August 5, 2021, 3:55pm UTC](https://discourse.cmake.org/t/findboost-ignores-all-hints-and-wont-find-the-right-installation/3883/1 "2021-08-05T15:55:37Z")

</div>

I’m trying to get some software built on CentOS 7 with modules. The boost module is loaded and `BOOST_DIR` is set as an environment variable to the appropriate path.

I’m trying to get FindBoost to pick up the module installation rather than the (older) system installation.

I have:

```auto
message( STATUS "BOOST_DIR: $ENV{BOOST_DIR}" )
if( NOT $ENV{BOOST_DIR} STREQUAL "" )
  message( STATUS "searching for boost in environment path: $ENV{BOOST_DIR}" )
  set( BOOST_ROOT $ENV{BOOST_DIR} )
  set( ENV{BOOST_ROOT} $ENV{BOOST_DIR} )
endif()
if( DEFINED BOOST_ROOT )
  message( STATUS "Setting boost installation location as: " ${BOOST_ROOT} )
  set( Boost_NO_SYSTEM_PATHS ON ) # only look in the user-specified location - nowhere else!
endif()

set( BOOST_MIN_VERSION "1.54.0" )
find_package( Boost ${BOOST_MIN_VERSION} MODULE REQUIRED COMPONENTS ${boost_comps} )

```

The `message` statements all output as expected, but then boost is not found. I’ve tried this with and without the `MODULE` keyword and it doesn’t make a difference.

**Version information:**

- cmake version: 3.18.2
- Boost version: 1.69.0

Is there some trick to make `FindBoost.cmake` actually respect the hints I’m passing it?

**Things I’ve tried:**

- Invoke cmake with `-DBOOST_LIBRARYDIR=$BOOST_DIR/lib -DBOOST_INCLUDEDIR=$BOOST_DIR/include`
- Invoke cmake with `-DBOOST_ROOT=$BOOST_DIR`

**Note** that I’m also setting `Boost_NO_SYSTEM_PATHS=ON`, but boost still reports that it found an “unsuitable” system install in `/usr` that wasn’t compatible with my specified minimum version.

So it seems that FindBoost is ignoring _everything_ I’m telling it about where to look.

Thanks for any tips!

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [August 5, 2021, 4:38pm UTC](https://discourse.cmake.org/t/findboost-ignores-all-hints-and-wont-find-the-right-installation/3883/2 "2021-08-05T16:38:34Z")

</div>

Does `cmake --debug-find` help out? There’s also the `Boost_DEBUG` variable you can use for `FindBoost` specifically.

---

<div class="post-metadata">

### Author: ![jsuthe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jsuthe/32/1656_2.png) [@jsuthe](https://discourse.cmake.org/u/jsuthe)
#### Post date: [August 5, 2021, 5:11pm UTC](https://discourse.cmake.org/t/findboost-ignores-all-hints-and-wont-find-the-right-installation/3883/4 "2021-08-05T17:11:14Z")

</div>

**Observations when using `Boost_DEBUG`:**

1. `BOOST_ROOT` is picked up correctly within `FindBoost`:  
`BOOST_ROOT = "/uufs/chpc.utah.edu/sys/installdir/boost/1.69.0i19-impi"`  
This is the location where boost is installed (the only subdirs there are `include` and `lib`).
2. FindBoost apparently ignores the fact that I’m setting `Boost_NO_SYSTEM_PATHS`. For example:
  - `_boost_LIBRARY_SEARCH_DIRS_RELEASE = "/usr/lib64;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH"`
  - `location of version.hpp: /usr/include/boost/version.hpp`  
I’m specifically trying to avoid the installation in `/usr` and find the one loaded by the module in the `/uufs` path.

This seemingly confirms my suspicion that FindBoost is ignoring all of the path information I’m trying to provide it.

**Observations when running with the `--debug-find` flag:**

1. I was able to confirm that no `Config` module was found (although it indicated that it looked in a large number of places for it, including system libraries). This is despite the fact that I had the `MODULE` keyword in the call to `find_package` (see original post).
2. The variable `CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH` contains the desired boost path, but also others including system level ones in `/usr`. My guess is that this is expected.

Any other tips?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [August 5, 2021, 5:32pm UTC](https://discourse.cmake.org/t/findboost-ignores-all-hints-and-wont-find-the-right-installation/3883/5 "2021-08-05T17:32:48Z")

</div>

> [@jsuthe](#):
>
> - `_boost_LIBRARY_SEARCH_DIRS_RELEASE = "/usr/lib64;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH"`
> - `location of version.hpp: /usr/include/boost/version.hpp`  
> I’m specifically trying to avoid the installation in `/usr` and find the one loaded by the module in the `/uufs` path.

Yes, the hard-coded `/usr/lib64` would be problematic. Is it fine if you remove that path (wherever it comes from)?

---

<div class="post-metadata">

### Author: ![jsuthe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jsuthe/32/1656_2.png) [@jsuthe](https://discourse.cmake.org/u/jsuthe)
#### Post date: [August 5, 2021, 5:55pm UTC](https://discourse.cmake.org/t/findboost-ignores-all-hints-and-wont-find-the-right-installation/3883/6 "2021-08-05T17:55:07Z")

</div>

Hmm - after all of this churn, wiping out my whole build directory and starting over made it work. So something must have been cached that broke things.

Sorry for the wild goose chase 😬

---

<div class="post-metadata">

### Author: ![Catherine\_Holloway](https://discourse.cmake.org/user_avatar/discourse.cmake.org/catherine_holloway/32/1958_2.png) [@Catherine\_Holloway](https://discourse.cmake.org/u/Catherine_Holloway)
#### Post date: [November 15, 2021, 12:57pm UTC](https://discourse.cmake.org/t/findboost-ignores-all-hints-and-wont-find-the-right-installation/3883/7 "2021-11-15T12:57:29Z")

</div>

I probably have a different problem, but I’m trying to build the same project with boost 1.69 on both Debian 9 and CentOS 7, and FindBoost works without any environment variables on Debian 9 but not CentOS 7.

I’ve noticed that on Debian 9, the headers/libs are installed in:  
/usr/include/boost

and on CentOS 7, these are in:

/usr/include/boost169/

I’m wondering if this differently named subdirectory is causing CMake to fail. It’s not obvious to me how to patch the module to get it to find this subdirectory.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 15, 2021, 2:13pm UTC](https://discourse.cmake.org/t/findboost-ignores-all-hints-and-wont-find-the-right-installation/3883/8 "2021-11-15T14:13:23Z")

</div>

I guess globbing for `/usr/include/boost*` may be necessary? Though I suspect that version-specific searching would get more complicated at that point.

---

<div class="post-metadata">

### Author: ![jsuthe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jsuthe/32/1656_2.png) [@jsuthe](https://discourse.cmake.org/u/jsuthe)
#### Post date: [November 15, 2021, 3:26pm UTC](https://discourse.cmake.org/t/findboost-ignores-all-hints-and-wont-find-the-right-installation/3883/9 "2021-11-15T15:26:37Z")

</div>

FYI, I found an issue with what I was originally doing here.  
Replace:

```auto
if( NOT $ENV{BOOST_DIR} STREQUAL "" )

```

with:

```auto
if( DEFINED ENV{BOOST_DIR} )

```

This seems to work as intended, while the first approach did not.
