21

I'm trying to use CMake to compile another library and it requires Boost.

I have installed both CMake and Boost using brew on OS X 10.10 Yosemite, but CMake refuses to find it. Boost is located in /usr/local/Cellar/boost/1.55.0_2

I've tried the following:

  • Setting -DBoost_DIR and -DBOOST_ROOT with the above path
  • Setting -DBoost_INCLUDE_DIR and -DBOOST_INCLUDEDIR with the above path + /include
  • Setting any and all of these options in the CMakeLists.txt file
  • Compiling Boost myself, and pointing the above vars to my own build
  • Trying out similar solutions to the same problem here, here, and here. The only answer that I found that mentioned brew on OS X was this one, and the same solution did not work for me.

Why is CMake blatantly ignoring my instructions? :(

Edit: CMake output from -DBoost_DEBUG=ON

Community
  • 1
  • 1
ttarik
  • 3,824
  • 1
  • 32
  • 51

3 Answers3

13

I found a separate homebrew package of boost-python. With it installed, CMake does find Boost:

brew install boost-python

gives me

> mkdir build ; ( cd build ; cmake .. )
-- The C compiler identification is AppleClang 6.0.0.6000056
-- The CXX compiler identification is AppleClang 6.0.0.6000056
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found PythonInterp: /usr/local/bin/python (found version "2.7.9")
-- Found PythonLibs: /usr/lib/libpython2.7.dylib (found version "2.7.5")
-- Boost version: 1.56.0
-- Found the following Boost libraries:
--   python
-- Configuring done
-- Generating done

(I have problems linking, but that's another story)

achimh
  • 352
  • 5
  • 8
  • It failed to located boost which followed http://stackoverflow.com/questions/33653001/unable-to-link-against-boost-python-on-os-x (For boost:python and python3) – Xb74Dkjb Nov 26 '15 at 17:08
  • Running `brew install boost-python` resulted in the error "Error: boost-python has been disabled because it does not build!". But `brew install boost` solved the issue for me. – Dan Saattrup Nielsen Feb 15 '22 at 16:35
5

I was also having trouble compiling something with C++/Python/Boost/CMake (Specifically, I was trying to build https://github.com/mapillary/OpenSfM).

I was getting an error like this

Linking CXX shared library .../OpenSfM/opensfm/csfm.so
Undefined symbols for architecture x86_64:
  "boost::python::instance_holder::deallocate(_object*, void*)", referenced from:
Undefined symbols for architecture x86_64:
"boost::python::instance_holder::deallocate(_object*, void*)", referenced from:
...

Inspired by the above comment, I tried to find this mythical "boost-python", but it didn't exist. Instead, I wound up using homebrew to reinstall normal boost with python.

brew install boost --with-python

That worked. CMake could now find boost and whatever python boost things it needed, and the compilation succeeded.

kathleen
  • 51
  • 1
  • 3
0

In my case upgrading both cmake and boost to their newest version solved the problem

brew upgrade boost cmake
MonsieurWave
  • 199
  • 3
  • 10