根据 boost python 的分步指导引发的 boost python 错误

Posted

技术标签:

【中文标题】根据 boost python 的分步指导引发的 boost python 错误【英文标题】:boost python errors raised on following step by step guidance from boost python 【发布时间】:2018-04-18 09:54:58 【问题描述】:

在尝试将我的 c++ 类“Car”转换为 python 模块时,我正在努力解决这个问题并得到大量的 boost 错误

来自 Car.h 的代码

#ifndef Carproj_CAR_H
#define Carproj_CAR_H
#include <string>


class Car 

public:
    Car(std::string & name, int & speed);
    void drive();

    void increaseSpeed();
private:
    std::string m_name;
    int m_speed;

;

Code from Car.cpp 

#include "Car.h"
#include <string>
#include <iostream>
#include <boost/python.hpp>
using namespace boost::python;




Car::Car(std::string & name, int & speed) 
    m_name = name;
    m_speed = speed;

void Car::drive() 

    std::cout << "Driving" << std::endl;


void Car::increaseSpeed() 

    m_speed+=30;




BOOST_PYTHON_MODULE(Car)
                
                 class_<Car>("Car",init<std::string, int>())
                               .def("drive",&Car::drive).def("increaseSpeed",&Car::increaseSpeed);
                

错误接收 - 整个消息:)

In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:57:0,
                 from /usr/include/boost/python/object/value_holder.hpp:50,
                 from /usr/include/boost/python/object/class_metadata.hpp:11,
                 from /usr/include/boost/python/class.hpp:23,
                 from /usr/include/boost/python.hpp:18,
                 from /home/damian/CLionProjects/Carproj/Car.cpp:8:
/usr/include/boost/python/object/value_holder.hpp: In instantiation of ‘boost::python::objects::value_holder<Value>::value_holder(PyObject*, A0, A1) [with A0 = boost::python::objects::reference_to_value<std::__cxx11::basic_string<char> >; A1 = int; Value = Car; PyObject = _object]’:
/usr/include/boost/python/object/make_holder.hpp:94:17:   required from ‘static void boost::python::objects::make_holder<2>::apply<Holder, ArgList>::execute(PyObject*, boost::python::objects::make_holder<2>::apply<Holder, ArgList>::t0, boost::python::objects::make_holder<2>::apply<Holder, ArgList>::t1) [with Holder = boost::python::objects::value_holder<Car>; ArgList = boost::mpl::vector2<std::__cxx11::basic_string<char>, int>; PyObject = _object; boost::python::objects::make_holder<2>::apply<Holder, ArgList>::t0 = std::__cxx11::basic_string<char>; boost::python::objects::make_holder<2>::apply<Holder, ArgList>::t1 = int]’
/usr/include/boost/python/detail/make_keyword_range_fn.hpp:63:47:   required from ‘boost::python::api::object boost::python::detail::make_keyword_range_constructor(const CallPolicies&, const keyword_range&, Holder*, ArgList*, Arity*) [with ArgList = boost::mpl::vector2<std::__cxx11::basic_string<char>, int>; Arity = boost::mpl::size<boost::mpl::vector2<std::__cxx11::basic_string<char>, int> >; Holder = boost::python::objects::value_holder<Car>; CallPolicies = boost::python::default_call_policies; boost::python::detail::keyword_range = std::pair<const boost::python::detail::keyword*, const boost::python::detail::keyword*>]’
/usr/include/boost/python/init.hpp:332:66:   required from ‘void boost::python::detail::def_init_aux(ClassT&, const Signature&, NArgs, const CallPoliciesT&, const char*, const keyword_range&) [with ClassT = boost::python::class_<Car>; CallPoliciesT = boost::python::default_call_policies; Signature = boost::mpl::vector2<std::__cxx11::basic_string<char>, int>; NArgs = boost::mpl::size<boost::mpl::vector2<std::__cxx11::basic_string<char>, int> >; boost::python::detail::keyword_range = std::pair<const boost::python::detail::keyword*, const boost::python::detail::keyword*>]’
/usr/include/boost/python/init.hpp:399:31:   required from ‘static void boost::python::detail::define_class_init_helper<0>::apply(ClassT&, const CallPoliciesT&, const Signature&, NArgs, const char*, const keyword_range&) [with ClassT = boost::python::class_<Car>; CallPoliciesT = boost::python::default_call_policies; Signature = boost::mpl::vector2<std::__cxx11::basic_string<char>, int>; NArgs = boost::mpl::size<boost::mpl::vector2<std::__cxx11::basic_string<char>, int> >; boost::python::detail::keyword_range = std::pair<const boost::python::detail::keyword*, const boost::python::detail::keyword*>]’
/usr/include/boost/python/init.hpp:171:67:   required from ‘void boost::python::init_base<DerivedT>::visit(classT&) const [with classT = boost::python::class_<Car>; DerivedT = boost::python::init<std::__cxx11::basic_string<char>, int>]’
/usr/include/boost/python/def_visitor.hpp:31:9:   required from ‘static void boost::python::def_visitor_access::visit(const V&, classT&) [with V = boost::python::def_visitor<boost::python::init<std::__cxx11::basic_string<char>, int> >; classT = boost::python::class_<Car>]’
/usr/include/boost/python/def_visitor.hpp:67:34:   required from ‘void boost::python::def_visitor<DerivedVisitor>::visit(classT&) const [with classT = boost::python::class_<Car>; DerivedVisitor = boost::python::init<std::__cxx11::basic_string<char>, int>]’
/usr/include/boost/python/class.hpp:226:9:   required from ‘boost::python::class_<T, X1, X2, X3>::self& boost::python::class_<T, X1, X2, X3>::def(const boost::python::def_visitor<Derived>&) [with Derived = boost::python::init<std::__cxx11::basic_string<char>, int>; W = Car; X1 = boost::python::detail::not_specified; X2 = boost::python::detail::not_specified; X3 = boost::python::detail::not_specified; boost::python::class_<T, X1, X2, X3>::self = boost::python::class_<Car>]’
/usr/include/boost/python/class.hpp:502:9:   required from ‘void boost::python::class_<T, X1, X2, X3>::initialize(const DefVisitor&) [with DefVisitor = boost::python::init_base<boost::python::init<std::__cxx11::basic_string<char>, int> >; W = Car; X1 = boost::python::detail::not_specified; X2 = boost::python::detail::not_specified; X3 = boost::python::detail::not_specified]’
/usr/include/boost/python/class.hpp:209:9:   required from ‘boost::python::class_<T, X1, X2, X3>::class_(const char*, const boost::python::init_base<DerivedT>&) [with DerivedT = boost::python::init<std::__cxx11::basic_string<char>, int>; W = Car; X1 = boost::python::detail::not_specified; X2 = boost::python::detail::not_specified; X3 = boost::python::detail::not_specified]’
/home/damian/CLionProjects/Carproj/Car.cpp:31:57:   required from here
/usr/include/boost/python/object/value_holder.hpp:137:13: error: binding ‘const std::__cxx11::basic_string<char>’ to reference of type ‘std::__cxx11::string& aka std::__cxx11::basic_string<char>&’ discards qualifiers
             BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
             ^
/home/damian/CLionProjects/Carproj/Car.cpp:14:1: note:   initializing argument 1 of ‘Car::Car(std::__cxx11::string&, int&)’
 Car::Car(std::string & name, int & speed) 
 ^
CMakeFiles/untitled1.dir/build.make:86: recipe for target 'CMakeFiles/untitled1.dir/Car.cpp.o' failed
make[3]: *** [CMakeFiles/untitled1.dir/Car.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/untitled1.dir/all' failed
make[2]: *** [CMakeFiles/untitled1.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/untitled1.dir/rule' failed
make[1]: *** [CMakeFiles/untitled1.dir/rule] Error 2
Makefile:118: recipe for target 'untitled1' failed
make: *** [untitled1] Error 2

使用cmake --build /home/damian/CLionProjects/Carproj/cmake-build-debug --target untitled1 -- -j 2 构建

非常感谢任何帮助

----新的----

根据 WinClouds 的建议再次出现新错误,让我感到困惑:(

Scanning dependencies of target untitled1
[ 33%] Building CXX object CMakeFiles/untitled1.dir/Car.cpp.o
[ 66%] Linking CXX executable untitled1
CMakeFiles/untitled1.dir/Car.cpp.o: In function `initCar':
/home/damian/CLionProjects/Carproj/Car.cpp:29: undefined reference to `boost::python::detail::init_module(char const*, void (*)())'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::type_info::name() const':
/usr/include/boost/python/type_id.hpp:165: undefined reference to `boost::python::detail::gcc_demangle(char const*)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::detail::none()':
/usr/include/boost/python/detail/none.hpp:16: undefined reference to `_Py_NoneStruct'
/usr/include/boost/python/detail/none.hpp:16: undefined reference to `_Py_NoneStruct'
/usr/include/boost/python/detail/none.hpp:16: undefined reference to `_Py_NoneStruct'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::api::object::object()':
/usr/include/boost/python/object_core.hpp:504: undefined reference to `_Py_NoneStruct'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `_object* boost::python::expect_non_null<_object>(_object*)':
/usr/include/boost/python/errors.hpp:45: undefined reference to `boost::python::throw_error_already_set()'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::class_<Car, boost::python::detail::not_specified, boost::python::detail::not_specified, boost::python::detail::not_specified>::class_<boost::python::init<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_> >(char const*, boost::python::init_base<boost::python::init<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_> > const&)':
/usr/include/boost/python/class.hpp:207: undefined reference to `boost::python::objects::class_base::class_base(char const*, unsigned long, boost::python::type_info const*, char const*)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `void boost::python::class_<Car, boost::python::detail::not_specified, boost::python::detail::not_specified, boost::python::detail::not_specified>::initialize<boost::python::init_base<boost::python::init<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_> > >(boost::python::init_base<boost::python::init<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_> > const&)':
/usr/include/boost/python/class.hpp:500: undefined reference to `boost::python::objects::class_base::set_instance_size(unsigned long)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `void boost::python::class_<Car, boost::python::detail::not_specified, boost::python::detail::not_specified, boost::python::detail::not_specified>::def_impl<Car, void (Car::*)(), boost::python::detail::def_helper<char const*, boost::python::detail::not_specified, boost::python::detail::not_specified, boost::python::detail::not_specified> >(Car*, char const*, void (Car::*)(), boost::python::detail::def_helper<char const*, boost::python::detail::not_specified, boost::python::detail::not_specified, boost::python::detail::not_specified> const&, ...)':
/usr/include/boost/python/class.hpp:537: undefined reference to `boost::python::objects::add_to_namespace(boost::python::api::object const&, char const*, boost::python::api::object const&, char const*)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::api::object boost::python::detail::make_function_aux<void (Car::*)(), boost::python::default_call_policies, boost::mpl::vector2<void, Car&>, mpl_::int_<0> >(void (Car::*)(), boost::python::default_call_policies const&, boost::mpl::vector2<void, Car&> const&, std::pair<boost::python::detail::keyword const*, boost::python::detail::keyword const*> const&, mpl_::int_<0>)':
/usr/include/boost/python/make_function.hpp:62: undefined reference to `boost::python::objects::function_object(boost::python::objects::py_function const&, std::pair<boost::python::detail::keyword const*, boost::python::detail::keyword const*> const&)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `void boost::python::objects::class_metadata<Car, boost::python::detail::not_specified, boost::python::detail::not_specified, boost::python::detail::not_specified>::maybe_register_class_to_python<Car>(Car*, mpl_::bool_<false>)':
/usr/include/boost/python/object/class_metadata.hpp:275: undefined reference to `boost::python::objects::copy_class_object(boost::python::type_info const&, boost::python::type_info const&)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::objects::py_function_impl_base::py_function_impl_base()':
/usr/include/boost/python/object/py_function.hpp:20: undefined reference to `vtable for boost::python::objects::py_function_impl_base'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::shared_ptr_from_python<Car>::shared_ptr_from_python()':
/usr/include/boost/python/converter/shared_ptr_from_python.hpp:25: undefined reference to `boost::python::converter::registry::insert(void* (*)(_object*), void (*)(_object*, boost::python::converter::rvalue_from_python_stage1_data*), boost::python::type_info, _typeobject const* (*)())'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `void boost::python::objects::register_dynamic_id<Car>(Car*)':
/usr/include/boost/python/object/inheritance.hpp:73: undefined reference to `boost::python::objects::register_dynamic_id_aux(boost::python::type_info, std::pair<void*, boost::python::type_info> (*)(void*))'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::to_python_converter<Car, boost::python::objects::class_cref_wrapper<Car, boost::python::objects::make_instance<Car, boost::python::objects::value_holder<Car> > >, true>::to_python_converter()':
/usr/include/boost/python/to_python_converter.hpp:87: undefined reference to `boost::python::converter::registry::insert(_object* (*)(void const*), boost::python::type_info, _typeobject const* (*)())'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::shared_ptr_from_python<Car>::convertible(_object*)':
/usr/include/boost/python/converter/shared_ptr_from_python.hpp:35: undefined reference to `_Py_NoneStruct'
/usr/include/boost/python/converter/shared_ptr_from_python.hpp:38: undefined reference to `boost::python::converter::get_lvalue_from_python(_object*, boost::python::converter::registration const&)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::shared_ptr_from_python<Car>::construct(_object*, boost::python::converter::rvalue_from_python_stage1_data*)':
/usr/include/boost/python/converter/shared_ptr_from_python.hpp:50: undefined reference to `boost::python::converter::shared_ptr_deleter::shared_ptr_deleter(boost::python::handle<_object>)'
/usr/include/boost/python/converter/shared_ptr_from_python.hpp:50: undefined reference to `boost::python::converter::shared_ptr_deleter::~shared_ptr_deleter()'
/usr/include/boost/python/converter/shared_ptr_from_python.hpp:58: undefined reference to `boost::python::converter::shared_ptr_deleter::~shared_ptr_deleter()'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::expected_from_python_type_direct<Car>::get_pytype()':
/usr/include/boost/python/converter/pytype_function.hpp:104: undefined reference to `boost::python::converter::registration::expected_from_python_type() const'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::shared_ptr<void>::shared_ptr<void, boost::python::converter::shared_ptr_deleter>(void*, boost::python::converter::shared_ptr_deleter)':
/usr/include/boost/smart_ptr/shared_ptr.hpp:358: undefined reference to `boost::python::converter::shared_ptr_deleter::~shared_ptr_deleter()'
/usr/include/boost/smart_ptr/shared_ptr.hpp:358: undefined reference to `boost::python::converter::shared_ptr_deleter::~shared_ptr_deleter()'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::registration const& boost::python::converter::detail::registry_lookup2<Car const volatile>(Car const volatile& (*)())':
/usr/include/boost/python/converter/registered.hpp:87: undefined reference to `boost::python::converter::registry::lookup(boost::python::type_info)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::detail::shared_count::shared_count<void*, boost::python::converter::shared_ptr_deleter>(void*, boost::python::converter::shared_ptr_deleter)':
/usr/include/boost/smart_ptr/detail/shared_count.hpp:171: undefined reference to `boost::python::converter::shared_ptr_deleter::operator()(void const*)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `_object* boost::python::objects::make_instance_impl<Car, boost::python::objects::value_holder<Car>, boost::python::objects::make_instance<Car, boost::python::objects::value_holder<Car> > >::execute<boost::reference_wrapper<Car const> const>(boost::reference_wrapper<Car const> const&)':
/usr/include/boost/python/object/make_instance.hpp:45: undefined reference to `boost::python::instance_holder::install(_object*)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::objects::make_holder<2>::apply<boost::python::objects::value_holder<Car>, boost::mpl::vector2<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >::execute(_object*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)':
/usr/include/boost/python/object/make_holder.hpp:92: undefined reference to `boost::python::instance_holder::allocate(_object*, unsigned long, unsigned long)'
/usr/include/boost/python/object/make_holder.hpp:94: undefined reference to `boost::python::instance_holder::install(_object*)'
/usr/include/boost/python/object/make_holder.hpp:98: undefined reference to `boost::python::instance_holder::deallocate(_object*, void*)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `_typeobject* boost::python::objects::make_instance<Car, boost::python::objects::value_holder<Car> >::get_class_object<boost::reference_wrapper<Car const> const>(boost::reference_wrapper<Car const> const&)':
/usr/include/boost/python/object/make_instance.hpp:66: undefined reference to `boost::python::converter::registration::get_class_object() const'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::objects::value_holder<Car>::value_holder<boost::python::objects::reference_to_value<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, int>(_object*, boost::python::objects::reference_to_value<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, int)':
/usr/include/boost/python/object/value_holder.hpp:137: undefined 
/usr/include/boost/python/object_core.hpp:213: undefined reference to `boost::python::objects::add_to_namespace(boost::python::api::object const&, char const*, boost::python::api::object const&, char const*)'
CMakeFiles/untitled1.dir/Car.cpp.o:(.rodata._ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFvP7_objectNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiENS0_21default_call_policiesENS_3mpl7vector4IvS6_SC_iEEEEEE[_ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFvP7_objectNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiENS0_21default_call_policiesENS_3mpl7vector4IvS6_SC_iEEEEEE]+0x30): undefined reference to `boost::python::objects::py_function_impl_base::max_arity() const'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::objects::caller_py_function_impl<boost::python::detail::caller<void (*)(_object*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int), boost::python::default_call_policies, boost::mpl::vector4<void, _object*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >::~caller_py_function_impl()':
/usr/include/boost/python/object/py_function.hpp:30: undefined reference to `boost::python::objects::py_function_impl_base::~py_function_impl_base()'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::detail::sp_counted_impl_pd<void*, boost::python::converter::shared_ptr_deleter>::~sp_counted_impl_pd()':
/usr/include/boost/smart_ptr/detail/sp_counted_impl.hpp:127: undefined reference to `boost::python::converter::shared_ptr_deleter::~shared_ptr_deleter()'
CMakeFiles/untitled1.dir/Car.cpp.o:(.rodata._ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIM3CarFvvENS0_21default_call_policiesENS_3mpl7vector2IvRS5_EEEEEE[_ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIM3CarFvvENS0_21default_call_policiesENS_3mpl7vector2IvRS5_EEEEEE]+0x30): undefined reference to `boost::python::objects::py_function_impl_base::max_arity() const'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::objects::caller_py_function_impl<boost::python::detail::caller<void (Car::*)(), boost::python::default_call_policies, boost::mpl::vector2<void, Car&> > >::~caller_py_function_impl()':
/usr/include/boost/python/object/py_function.hpp:30: undefined reference to `boost::python::objects::py_function_impl_base::~py_function_impl_base()'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::objects::value_holder<Car>::~value_holder()':
/usr/include/boost/python/object/value_holder.hpp:43: undefined reference to `boost::python::instance_holder::~instance_holder()'
CMakeFiles/untitled1.dir/Car.cpp.o:(.rodata._ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFvP7_objectNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiENS0_21default_call_policiesENS_3mpl7vector4IvS6_SC_iEEEEEE[_ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFvP7_objectNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiENS0_21default_call_policiesENS_3mpl7vector4IvS6_SC_iEEEEEE]+0x10): undefined reference to `typeinfo for boost::python::objects::py_function_impl_base'
CMakeFiles/untitled1.dir/Car.cpp.o:(.rodata._ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIM3CarFvvENS0_21default_call_policiesENS_3mpl7vector2IvRS5_EEEEEE[_ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIM3CarFvvENS0_21default_call_policiesENS_3mpl7vector2IvRS5_EEEEEE]+0x10): undefined reference to `typeinfo for boost::python::objects::py_function_impl_base'
CMakeFiles/untitled1.dir/Car.cpp.o:(.rodata._ZTIN5boost6python7objects12value_holderI3CarEE[_ZTIN5boost6python7objects12value_holderI3CarEE]+0x10): undefined reference to `typeinfo for boost::python::instance_holder'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::detail::sp_counted_impl_pd<void*, boost::python::converter::shared_ptr_deleter>::dispose()':
/usr/include/boost/smart_ptr/detail/sp_counted_impl.hpp:153: undefined reference to `boost::python::converter::shared_ptr_deleter::operator()(void const*)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::objects::value_holder<Car>::holds(boost::python::type_info, bool)':
/usr/include/boost/python/object/value_holder.hpp:96: undefined reference to `boost::python::objects::find_static_type(void*, boost::python::type_info, boost::python::type_info)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::arg_rvalue_from_python<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::arg_rvalue_from_python(_object*)':
/usr/include/boost/python/converter/arg_from_python.hpp:299: undefined reference to `boost::python::converter::rvalue_from_python_stage1(_object*, boost::python::converter::registration const&)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::arg_rvalue_from_python<int>::arg_rvalue_from_python(_object*)':
/usr/include/boost/python/converter/arg_from_python.hpp:299: undefined reference to `boost::python::converter::rvalue_from_python_stage1(_object*, boost::python::converter::registration const&)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::expected_pytype_for_arg<void>::get_pytype()':
/usr/include/boost/python/converter/pytype_function.hpp:68: undefined reference to `boost::python::converter::registry::query(boost::python::type_info)'
/usr/include/boost/python/converter/pytype_function.hpp:69: undefined reference to `boost::python::converter::registration::expected_from_python_type() const'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::expected_pytype_for_arg<_object*>::get_pytype()':
/usr/include/boost/python/converter/pytype_function.hpp:68: undefined reference to `boost::python::converter::registry::query(boost::python::type_info)'
/usr/include/boost/python/converter/pytype_function.hpp:69: undefined reference to `boost::python::converter::registration::expected_from_python_type() const'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::expected_pytype_for_arg<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::get_pytype()':
/usr/include/boost/python/converter/pytype_function.hpp:68: undefined reference to `boost::python::converter::registry::query(boost::python::type_info)'
/usr/include/boost/python/converter/pytype_function.hpp:69: undefined reference to `boost::python::converter::registration::expected_from_python_type() const'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::expected_pytype_for_arg<int>::get_pytype()':
/usr/include/boost/python/converter/pytype_function.hpp:68: undefined reference to `boost::python::converter::registry::query(boost::python::type_info)'
/usr/include/boost/python/converter/pytype_function.hpp:69: undefined reference to `boost::python::converter::registration::expected_from_python_type() const'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::reference_arg_from_python<Car&>::reference_arg_from_python(_object*)':
/usr/include/boost/python/converter/arg_from_python.hpp:283: undefined reference to `boost::python::converter::get_lvalue_from_python(_object*, boost::python::converter::registration const&)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::expected_pytype_for_arg<Car&>::get_pytype()':
/usr/include/boost/python/converter/pytype_function.hpp:68: undefined reference to `boost::python::converter::registry::query(boost::python::type_info)'
/usr/include/boost/python/converter/pytype_function.hpp:69: undefined reference to `boost::python::converter::registration::expected_from_python_type() const'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::registration const& boost::python::converter::detail::registry_lookup2<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const volatile>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const volatile& (*)())':
/usr/include/boost/python/converter/registered.hpp:87: undefined reference to `boost::python::converter::registry::lookup(boost::python::type_info)'
CMakeFiles/untitled1.dir/Car.cpp.o: In function `boost::python::converter::registration const& boost::python::converter::detail::registry_lookup2<int const volatile>(int const volatile& (*)())':
/usr/include/boost/python/converter/registered.hpp:87: undefined reference to `boost::python::converter::registry::lookup(boost::python::type_info)'
collect2: error: ld returned 1 exit status
CMakeFiles/untitled1.dir/build.make:120: recipe for target 'untitled1' failed
make[3]: *** [untitled1] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/untitled1.dir/all' failed
make[2]: *** [CMakeFiles/untitled1.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/untitled1.dir/rule' failed
make[1]: *** [CMakeFiles/untitled1.dir/rule] Error 2
Makefile:118: recipe for target 'untitled1' failed
make: *** [untitled1] Error 2

如果有人知道任何材料,因为我对 Boost Python 完全陌生,这将很有用,因为这种错误消息流令人难以置信

达米安

【问题讨论】:

嗨!如果您签出POST Format 以备将来在堆栈溢出时的努力会更好。 -谢谢 请添加完整的错误消息,目前仅打印参考,并且缺少编译器抱怨的真正错误。 最好的方法是完全删除对构造函数中参数的引用,如下所示:Car(const std::string name, int speed)。 int 的引用在这里没有意义,因为引用和 int 本身一样大并且没有优势,std::string 在大多数实现中都会在内部引用,所以这也没有额外的成本。 好吧,这是有道理的,但它似乎并没有消除错误? 【参考方案1】:

Class Car 的参数的构造函数需要一个非常量的引用,所以它只接受左值。

但是Python导出的类模板是临时值,是右值,不能作为构造函数的参数。

因此,您可以将 Car 的构造函数参数的参数更改为 const 引用。像这样:

Car(const std::string & name, const int & speed);

【讨论】:

您好 WinCloud,我不太明白您的意思。为什么在这种情况下将其设为 const 参考有帮助。导出的类模板需要我指定的参数,这取决于 boost python 的解释。此外,我已根据您的建议更改了这一点,并在上述描述中添加了类似的错误。感谢您的帮助

以上是关于根据 boost python 的分步指导引发的 boost python 错误的主要内容,如果未能解决你的问题,请参考以下文章

boost::python:如何覆盖静态属性?

无法在 Visual Studio 2008 中构建 Boost.python。编译出错

boost::thread interrupt() 仅在第一次执行中断点时引发异常?

boost::regex 中的嵌套量词

使用Boost.Python修复未解析的外部符号

python的异步C++库