我有小型cpp程序:
#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);
}
我正在使用cmake对其进行编译以作为python 3库运行。我正在使用此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 "" )
我可以成功运行cmake,但是当我尝试运行make命令时,我会得到
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
我尝试使用--with-python = python3.5m参数重新安装boost几次,使用的方法很少,使用g ++手工编译,从https://github.com/TNG/boost-python-examples运行示例,并且每次我获得未定义的引用时。我使用linux,默认python是python 3.5。我阅读了所有与boost-python有关的堆栈溢出问题的答案,但没有一个对我有帮助。我还能尝试什么?