2

I was using Boost 1.54.0 and it was located in "/usr/include". We blew that away and installed Boost 1.57.0. It got installed in "/usr/local/include".

Now, my CLion project, which uses CMake cannot find the Boost library. Here is my CMakeLists.txt file:

enter image description here

And here are my errors:

enter image description here

I have no idea how to make CMake look in the correct place for Boost.

Patricia
  • 5,019
  • 14
  • 72
  • 152
  • it seems you've forgot to add `CMakeLists.txt` contents and error description. – zaufi Apr 14 '15 at 05:34
  • For code (also CMake code), please use copy and paste, select the pasted code and press on the `{}` button – Antonio Apr 14 '15 at 07:57

1 Answers1

3

According to the FindBoost documentation (http://www.cmake.org/cmake/help/v3.1/module/FindBoost.html), you can set a CMake variable BOOST_ROOT to give CMake a hint about where to look.

In your CMakeLists.txt file, you can add the following before the find_package(Boost...) line:

set(BOOST_ROOT /usr/local)

Update: I agree with the comments that putting machine specific configuration parameters directly in CMakeLists.txt is not best practice.

As an alternative to directly setting this variable, you can pass options like this to the cmake process in CLion by doing the following:

Navigate to File -> Settings... -> Build, Execution, and Deployment -> CMake. Under Generation, add -DBOOST_ROOT=/usr/local to CMake options.

John Drouhard
  • 1,209
  • 2
  • 12
  • 18
  • 1
    … or use `-DBOOST_ROOT=/some/path` CLI option when run `cmake` – zaufi Apr 14 '15 at 04:24
  • 1
    That works if you are generating your build directory on the command line, but this question was about setting the boost prefix path in a CLion project. Another option would be to manually edit the CMake cache in CLion itself. – John Drouhard Apr 14 '15 at 04:43
  • 1
    having "hardcoded" (specific to developer's host) paths in `CMakeLists.txt` is a bad idea anyway. – zaufi Apr 14 '15 at 05:32
  • 1
    +1 for good link to documentation. However, zaufi is right. My suggestion would be to set a cached variable `set(BOOST_CUSTOM_ROOT "" CACHE STRING "Hint for boost installation location")` and then check if the user modifies this variable, `if(BOOST_CUSTOM_ROOT)` `set(BOOST_ROOT ${BOOST_CUSTOM_ROOT})` `endif()` The user can modify this variable for example from cmake-gui (with this trick, after the first configure the variable is available), command line or any other tool associated to CLion. – Antonio Apr 14 '15 at 08:11
  • @JohnDrouhard - I'm having some linking issues. The question is here: http://stackoverflow.com/q/29638539/1735836 If you're interested!! :-) – Patricia Apr 14 '15 at 22:38