I am trying to build this simple boost python demo from this link on my MacOS High Sierra.
Following is the hello_ext.cpp
:
#include <boost/python.hpp>
char const* greet()
{
return "hello, world";
}
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
Following is the CmakeLists.txt
:
cmake_minimum_required(VERSION 3.5)
# Find python and Boost - both are required dependencies
find_package(PythonLibs 2.7 REQUIRED)
find_package(Boost COMPONENTS python REQUIRED)
# Without this, any build libraries automatically have names "lib{x}.so"
set(CMAKE_SHARED_MODULE_PREFIX "")
# Add a shared module - modules are intended to be imported at runtime.
# - This is where you add the source files
add_library(hello_ext MODULE hello_ext.cpp)
# Set up the libraries and header search paths for this target
target_link_libraries(hello_ext ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
target_include_directories(hello_ext PRIVATE ${PYTHON_INCLUDE_DIRS})
I figured I need to install python. Boost 1.69 was already installed and I did brew install boost-python
which worked fine. Doing a brew list | grep 'boost'
lists out boost
and boost-python
.
But, doing a cmake ..
from a build
directory complains the following:
Could not find the following Boost libraries:
boost_python
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to
the directory containing Boost libraries or BOOST_ROOT to the location
of Boost.
What am I missing here?
cmake --trace
or--trace-expand
is very useful for debugging CMake logic. Find the error message in CMake stock scripts, then compare the code with the corresponding place in the trace to see what's happening. – Mercerizefind_package(Boost COMPONENTS python27 REQUIRED)
instead? – Albigensesfind_package(Boost COMPONENTS python27 REQUIRED)
fixed it :D. Great. Thanks. Looks like I should write the correct python version while asking cmake to locate python – Thicket