4

I want to build a library called CSWNet on my machine. Cmake can find Boost_INCLUDE_DIR and Boost_LIB_DIR but it cannot find an option called Boost_DIR which is a directory containing a CMake configuration file for Boost. Where is it? Please help, thanks ahead. The error I got is shown below and I installed boost from ubuntu repository and it's installed in /usr/local.

 CMake Error at /usr/local/share/cmake-2.8/Modules/FindBoost.cmake:429 (message):
When requesting a specific version of Boost, you must provide at least the
major and minor version numbers, e.g., 1.34
Call Stack (most recent call first):
demos/CMakeLists.txt:149 (find_package)
ComicSansMS
  • 51,484
  • 14
  • 155
  • 166
Juneyee
  • 389
  • 2
  • 6
  • 15
  • Can you share some details about your Operative System/environment and how/where did you install boost? – Antonio Jul 10 '13 at 10:16
  • Hi @Antonio, I've edited my question and added some details. – Juneyee Jul 10 '13 at 10:58
  • Some versions of Boost use the flag `Boost_INCLUDE_DIR` and others use the flag `Boost_INCLUDEDIR` (**without the underscore**). You can check the right one for your case by reading the `FindBoost.cmake` file, under `path-to-cmake/Modules/FindBoost.cmake` – marcelosalloum Jul 05 '19 at 14:03

2 Answers2

10

It seems you misunderstood the meaning of Boost_DIR.

Boost_DIR is an environment variable used as a hint by CMake to find the boost installation directory. If this is set to Boost_DIR-NOTFOUND that does not mean that it did not find Boost. Boost_FOUND is used to indicate whether the search was successful:

find_package(Boost REQUIRED thread)
if(Boost_FOUND)
    message(STATUS "Success!")
endif()

In case of a successful search, CMake will also print a diagnostic message during the configure phase which looks something like

Boost version: 1.53.0
Found the following Boost libraries:
  thread
ComicSansMS
  • 51,484
  • 14
  • 155
  • 166
  • Thanks CommicSansMS, that makes sense to me, I did get Boost_DIR set to be Boost_DIR-NOTFOUND. But I'm still confused how I can fix this problem. I installed boost under /usr/local. do you mean what I need to do is to add Boost_DIR as a environment variable to my system like export Boost_DIR = /usr/local/... ? – Juneyee Jul 10 '13 at 11:03
  • CMake is known for having problems finding stuff in `/usr/local`. You could try using [CMAKE_PREFIX_PATH](http://www.cmake.org/cmake/help/v2.8.11/cmake.html#variable:CMAKE_PREFIX_PATH) to solve this. Alternatively the `BOOST_ROOT` environment variable [seems to be the preferred way](http://www.cmake.org/cmake/help/v2.8.11/cmake.html#module:FindBoost) to give hints on the location of Boost nowadays. `Boost_DIR` is only used if Boost itself was build with CMake and provides a package configuration with an exported target. – ComicSansMS Jul 10 '13 at 11:18
  • The links above are very useful. So I think I need to rebuild Boost with CMake. I've checked the [guide](https://svn.boost.org/trac/boost/wiki/CMakeConfigAndBuild) provided by BOOST about how to build boost with cmake. But the files downloaded contains no CMakeLists.txt. – Juneyee Jul 10 '13 at 12:52
  • I found that boost of version 1_40_0 contains the CMakeList.txt. It's becoming more and more complicated now. [The up-to-date gcc doesn't support boost under version 1.48.0 because Boost.Threads failed to correctly detect thread support in the compiler.](http://stackoverflow.com/questions/8297652/error-boost-disable-threads) But I can NOT find any version above 1.48.0 have a CMakeList.txt. – Juneyee Jul 10 '13 at 13:15
  • 2
    @JohnnyHan Building Boost yourself with CMake is currently not supported due to [complex reasons](https://svn.boost.org/trac/boost/wiki/CMakeModularizationStatus) but may be possible in the future. But you don't need to rebuild Boost. It should also work with the binaries, you just have to point CMake to the right path. Ususally setting the `BOOST_ROOT` and possibly `Boost_ADDITIONAL_VERSIONS` is enough. As with any of CMake's find scripts, the difficult part is understanding the logic that is used to find the files on disk. Unfortunately, in case of Boost that logic is particularly complex. – ComicSansMS Jul 10 '13 at 14:54
3

Hope its not too late to post this. Passing it in the command line along with cmake command would resovle it

 cmake -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=dist -DBOOST_DIR="boost installation location"
ravi.zombie
  • 1,482
  • 1
  • 20
  • 23