Boost Python导入失败,未定义包装类的符号

问题描述 投票:0回答:1

我在当前项目中使用boost python时遇到问题。当我尝试在python 3.6中导入生成的模块时,以下错误显示:ImportError:PythonTrackWrapper.so:undefined symbol:_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);
}

的CMakeLists.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})

这是我认为最有可能包含与问题相关的错误的代码,如果您认为原因可能在其他地方,我会很乐意发布其余的。

非常感谢你!

c++ boost boost-python
1个回答
0
投票

我发现了我的错误,问题是我在我的.h文件中定义了一个析构函数,然后我没有实现。希望能帮助别人。

© www.soinside.com 2019 - 2024. All rights reserved.