Communication errors Boost.Python and CMake and downloads

I have main.cppthis:

#include <boost/python.hpp>

const char* greeting()
{
    return "Hello world?";
}

BOOST_PYTHON_MODULE(test)
{
    using namespace boost::python;

    def("greeting", greeting);
}

And file CMakeLists.txt:

project(test)
cmake_minimum_required(VERSION 2.8)

# get boost
set(Boost_USE_STATIC_LIBS   ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS
                system
                thread
                python
             REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})

# get python
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
link_directories(${PYTHON_LIBRARIES})

add_library(test SHARED
        main.cpp
    )

I can run cmakeand makejust fine. It displays me a small file libtest.sofor me. To test this, I have a Python script, for example:

import libtest

print(libtest.greeting())

Running this in the same directory as libtest.sogives the following error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import libtest
ImportError: /home/travis/projects/boost-python-test/build/libtest.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv

Hop! The problem with the concept make VERBOSE=1... the line creating mine libtest.solooks like this:

/usr/bin/c++  -fPIC   -shared -Wl,-soname,libtest.so -o libtest.so CMakeFiles/test.dir/main.cpp.o -L/usr/lib/libpython2.7.so

I have a mental block why I do not see -L/usr/lib/libboost_python-mt-py27.athis line. He obviously worked for find_package(PythonLibs ...). I am falling due to some new CMake beginners.

+5
source share
1 answer

. target_link_libraries add_library.

target_link_libraries(test
        ${Boost_LIBRARIES}
        ${PYTHON_LIBRARIES}
    )

, Python . ?

+8

All Articles