3

I have small cpp program:

#include <iostream>
#include <boost/python.hpp>
//#include <boost/python/numpy.hpp>

void helloxd(){
    std::cout<<std::endl<<"something"<<std::endl;
}

BOOST_PYTHON_MODULE(tkbd_cpp)
{
    using namespace boost::python;
    def("helloxd_cpp", helloxd);
}

I'm using cmake to compile it to run as python 3 library. Im using this CMakeLists.txt

cmake_minimum_required( VERSION 3.5 )



project( tkbd_cpp )

set(CMAKE_CXX_FLAGS "-Wl,--no-undefined")
set(BOOST_ROOT /usr/boost)
set(PYTHON_LIBRARY /usr/lib/python3.5 )
set(PYTHON_INCLUDE_DIR /usr/include/python3.5m )
find_package(PythonInterp 3.5 REQUIRED)
find_package(PythonLibs 3.5 REQUIRED)
find_package(Boost 1.54 REQUIRED COMPONENTS system python)

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} )

ADD_LIBRARY(tkbd_cpp SHARED py_wrapper.cpp)
TARGET_LINK_LIBRARIES(tkbd_cpp ${Boost_LIBRARIES} ${PythonLibs_LIBRARIES})
set_target_properties( tkbd_cpp PROPERTIES PREFIX "" )

I can succesfully run cmake ., but when i try to run make command i get

CMakeFiles/tkbd_cpp.dir/py_wrapper.cpp.o: In function `PyInit_tkbd_cpp':
py_wrapper.cpp:(.text+0xcf): undefined reference to `boost::python::detail::init_module(PyModuleDef&, void (*)())'
CMakeFiles/tkbd_cpp.dir/py_wrapper.cpp.o: In function `boost::python::detail::none()':
py_wrapper.cpp:(.text._ZN5boost6python6detail4none

I tried reinstalling boost several times, with few methods, with --with-python=python3.5m argument, compiling by hand with g++, runing example from https://github.com/TNG/boost-python-examples , and every time I get undefined reference. I use linux, and default python is python 3.5. I read all answers connected with boost-python on stack-overflow and non of them helped me. What else could I try?

  • @πάντα ῥεῖ I dont see how this question is duplicate to the one linked, there is nothing that could help me with this problem – Black_Magic Mar 24 '19 at 16:43
  • 2
    Modern [FindBoost.cmake](https://cmake.org/cmake/help/v3.13/module/FindBoost.html) prefers `python` component to be specified **with version**, like `python35`. `PythonLibs_LIBRARIES` is a wrong variable name for `PythonLibs` package. [Correct one](https://cmake.org/cmake/help/v3.10/module/FindPythonLibs.html) is `PYTHON_LIBRARIES`. And variable `CMAKE_CXX_FLAGS` is a wrong place for **linker flags** `-Wl,...`. You may add these flags directly in `target_link_libraries` call. – Tsyvarev Mar 24 '19 at 18:52
  • Anycase, as there is a **clear attempt** to link proper libraries, the question is not a duplicate for generic "What is undefined reference" one. – Tsyvarev Mar 24 '19 at 18:57

0 Answers0