提升 Python 导入失败,未定义包装类的符号
Boost Python import fails, symbol of wrapped class not defined
我在当前项目中使用 boost python 时遇到问题。当我尝试在python 3.6中导入生成的模块时,显示以下错误:ImportError:PythonTrackWrapper.so:未定义的符号:_ZN18PythonTrackWrapperD1Ev其中PythonTrackWrapper是我想包装以便在Python中使用的类。我无法追踪错误,感谢您的帮助!
PythonTrackWrapper.cpp:
#include <Python.h>
#include <boost/python.hpp>
#include <boost/tuple/tuple.hpp>
using namespace boost::python;
PythonTrackWrapper::PythonTrackWrapper(std::vector<boost::tuple<double, double>>& left, std::vector<boost::tuple<double, double>>& right, boost::tuple<double, double>& currentPose){
std::vector<double> X, Y;
produceTrack(left, right, currentPose, X, Y);
track = Track(X, Y);
}
BOOST_PYTHON_MODULE(PythonTrackWrapper)
{
class_<PythonTrackWrapper>("PythonTrackWrapper", init<std::vector<boost::tuple<double, double>>&, std::vector<boost::tuple<double, double>>&, boost::tuple<double, double>&>())
.def("get_progress_on_track", &PythonTrackWrapper::getProgressOntrack);
}
CMakeList.txt
cmake_minimum_required(VERSION 3.5)
project(Spline)
set(CMAKE_CXX_STANDARD 17)
find_package(Boost COMPONENTS python3 REQUIRED)
find_package(Python3 3.6 REQUIRED)
...
add_library(PythonTrackWrapper SHARED PythonTrackWrapper.cpp)
set_target_properties(PythonTrackWrapper PROPERTIES SUFFIX .so)
set_target_properties(PythonTrackWrapper PROPERTIES PREFIX "")
target_link_libraries(PythonTrackWrapper Spline boost_python3 ${Boost_LIBRARIES} ${Python3_LIBRARIES})
这是我认为最有可能包含与问题相关的错误的代码,如果您认为原因可能在其他地方,我很乐意发布其余的。
谢谢!
我发现了我的错误,问题是我在 .h 文件中定义了一个析构函数,但我没有实现它。希望对某人有所帮助。
相关文章:
- 简化在 Pybind11 中为 C++ 模板类生成包装类:模板声明不能出现在块范围内
- C++-用与被包装数据相同的语法构造包装类
- C++-用和结构相同的语法围绕结构构造包装类
- C++泛型包装类,它为某些函数添加了额外的处理
- 如何减少大量包装类的实现代码?
- 在 C++ 中为 C 样式对象创建一个透明包装类
- 如何将包装类的对象用作包装函数中的参数
- 这->...在模板包装类中必需
- 无法理解包装类的构造函数的声明
- 标准向量之上的 C++11 包装类
- 消息:: Simbolo使用未定义的类符号
- 编写安全包装类以管理用户定义对象的指针
- 重构现有包装类,以使用与包装器本身相同的构造函数参数包装 T
- 包装类设计和依赖注入
- 提升 Python 导入失败,未定义包装类的符号
- 简单包装类与智能指针
- 将 C 结构工厂函数与其相应的 C++ 包装类构造函数合并
- 为什么这个C++包装类没有内联掉
- std::variant、包装类和'conversion from ... to non-scalar type ... requested'
- C# 使用包装类中的字符串参数调用 C++ 方法