【发布时间】:2021-05-16 12:17:30
【问题描述】:
我正在尝试在我的 python 项目中运行 C++ 代码。 这是recompile.sh,它很好地构建了共享对象。
g++ -fPIC -shared -I /home/pathto python/python3.8/ src/example.hpp \
/usr/lib/x86_64-linux-gnu/libboost_python38.so -o src/example.so
example.hpp:
#include <boost/python.hpp>
int get_answer_c(){
return 42;
}
BOOST_PYTHON_MODULE(example){
boost::python::def("get_answer", get_answer_c);
}
当我尝试导入模块时 example 我收到此错误:
AttributeError: ./src/example.so: undefined symbol: get_answer
【问题讨论】:
-
如何导入?显示有问题的代码。
标签: python c++ c python-3.x