编译时将错误与Boost.python链接 [英] Linking error with Boost.python while compiling

查看:79
本文介绍了编译时将错误与Boost.python链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在尝试构建受这里

我的初衷是能够从Python内部调用C ++代码.我只是运行Boost文档中的示例以实现此目标.

My original intention is to be able to call C++ code from within Python. I'm just running the examples from the Boost documentation in order to achieve this goal.

这是我的makefile文件

Here's my makefile

CXX               := g++
CXX_FLAGS         := -Wall -Wextra -std=c++17 -ggdb

BIN               := bin
SRC               := src
INCLUDE           := inc
LIB               := lib

BOOST_ROOT        := /home/eicossa/repo/boost_install
BOOST_INCL        := ${BOOST_ROOT}/include/
BOOST_LIBS        := ${BOOST_ROOT}/libs/ 

PYTHON_INCL       := /usr/include/python3.7m/
PYTHON_LIBS       := /usr/lib/python3.7/

LIBFLAGS          := -lboost_system 
EXECUTABLE        := greet


all: $(BIN)/$(EXECUTABLE)

run: clean all
        clear
        ./$(BIN)/$(EXECUTABLE)

$(BIN)/$(EXECUTABLE): $(SRC)/*.cpp 
        $(CXX) $(CXX_FLAGS) -I$(PYTHON_INCL) -I$(INCLUDE) -I$(BOOST_INCL) -L$(BOOST_LIBS) -L$(PYTHON_LIBS) -L$(LIB$

clean:
        -rm $(BIN)/*

这会导致以下错误

/tmp/ccNVjFX3.o:在函数 boost :: python :: api :: object :: object()'中:/home/eicossa/repo/boost_install/include/boost/python/object_core.hpp:400: _Py_NoneStruct'/tmp/ccQNpbxG.o的未定义引用:在函数中 PyInit_hello_ext':/home/eicossa/Dropbox/wtcd/license/boost/src/bindings.cpp:3:未定义引用 boost :: python :: detail :: init_module(PyModuleDef& ;, void()())'/tmp/ccQNpbxG.o:在函数 boost :: python :: type_info :: name()中const':/home/eicossa/repo/boost_install/include/boost/python/type_id.hpp:160:未定义对 boost :: python :: detail :: gcc_demangle(charconst )'/tmp/ccQNpbxG.o:在函数中 boost :: python :: to_python_value< char const * const&> :: operator()(charconst * const&)const':/home/eicossa/repo/boost_install/include/boost/python/converter/builtin_converters.hpp:157:未定义的引用 boost :: python :: converter :: do_return_to_python(char const *)'/tmp/ccQNpbxG.o:在函数 boost :: python :: to_python_value< char中const * const& :: get_pytype()const':/home/eicossa/repo/boost_install/include/boost/python/converter/builtin_converters.hpp:157:未定义对 PyUnicode_Type的引用"/tmp/ccQNpbxG.o:在函数中 void boost :: python :: def< char const *(*)()>(char const *,char const *(*)())':/home/eicossa/repo/boost_install/include/boost/python/def.hpp:91:未定义对 boost :: python :: detail :: scope_setattr_doc(charconst *,boost :: python :: api :: object const& ;, char const *)'/tmp/ccQNpbxG.o:在功能`boost :: python :: api :: object中boost :: python :: detail :: make_function_aux

/tmp/ccNVjFX3.o: In function boost::python::api::object::object()': /home/eicossa/repo/boost_install/include/boost/python/object_core.hpp:400: undefined reference to_Py_NoneStruct' /tmp/ccQNpbxG.o: In function PyInit_hello_ext': /home/eicossa/Dropbox/wtcd/license/boost/src/bindings.cpp:3: undefined reference toboost::python::detail::init_module(PyModuleDef&, void ()())' /tmp/ccQNpbxG.o: In function boost::python::type_info::name() const': /home/eicossa/repo/boost_install/include/boost/python/type_id.hpp:160: undefined reference toboost::python::detail::gcc_demangle(char const)' /tmp/ccQNpbxG.o: In function boost::python::to_python_value<char const* const&>::operator()(char const* const&) const': /home/eicossa/repo/boost_install/include/boost/python/converter/builtin_converters.hpp:157: undefined reference to boost::python::converter::do_return_to_python(char const*)' /tmp/ccQNpbxG.o: In function boost::python::to_python_value<char const* const&>::get_pytype() const': /home/eicossa/repo/boost_install/include/boost/python/converter/builtin_converters.hpp:157: undefined reference toPyUnicode_Type' /tmp/ccQNpbxG.o: In function void boost::python::def<char const* (*)()>(char const*, char const* (*)())': /home/eicossa/repo/boost_install/include/boost/python/def.hpp:91: undefined reference toboost::python::detail::scope_setattr_doc(char const*, boost::python::api::object const&, char const*)' /tmp/ccQNpbxG.o: In function `boost::python::api::object boost::python::detail::make_function_aux

(char const *(*)(),boost :: python :: default_call_policies const& boost :: mpl :: vector1 const&)':/home/eicossa/repo/boost_install/include/boost/python/make_function.hpp:38:未定义的引用 boost :: python :: objects :: function_object(boost :: python :: objects :: py_functionconst&)'/tmp/ccQNpbxG.o:在函数中 boost :: python :: objects :: py_function_impl_base :: py_function_impl_base()':/home/eicossa/repo/boost_install/include/boost/python/object/py_function.hpp:20:未定义对 vtable的引用boost :: python :: objects :: py_function_impl_base'/tmp/ccQNpbxG.o:(.rodata._ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE[_ZTVN5boost6python7objectsFP7_ES_EE_IP_0__IS_EE_IP_0_6_7_sip_FP_6_EE_IP_0_IE_EE_IP_0_6_7_sip_FP_0_6未定义的引用 boost :: python :: objects :: py_function_impl_base :: max_arity()const'/tmp/ccQNpbxG.o:在函数中 boost :: python :: objects :: caller_py_function_impl< boost :: python :: detail :: caller< charconst *(*)(),boost :: python :: default_call_policies,boost :: mpl :: vector1< char const *>>> :: ~~ caller_py_function_impl()':/home/eicossa/repo/boost_install/include/boost/python/object/py_function.hpp:30:未定义的引用 boost :: python :: objects :: py_function_impl_base ::〜py_function_impl_base()'/tmp/ccQNpbxG.o:(.rodata._ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE[_ZTIN5boost6python7IPs_EE_EE_EE_EE_EP_6_EE_EP_6_EE_EE_EE_EP_6_EE1_6_EE_EE_EE_IP_6_IP_IE_EE_EE_EE6_EE_IP_IE_EE_EE6_EE_EE_IP_6_7未定义对 typeinfo的引用boost :: python :: objects :: py_function_impl_base'/tmp/ccQNpbxG.o:在函数 boost :: python :: converter :: expected_pytype_for_arg :: get_pytype()':/home/eicossa/repo/boost_install/include/boost/python/converter/pytype_function.hpp:69:未定义的引用 boost :: python :: converter :: registry :: query(boost :: python :: type_info)'/home/eicossa/repo/boost_install/include/boost/python/converter/pytype_function.hpp:70:未定义的引用 boost :: python :: converter :: registration :: expected_from_python_type()const'collect2:错误:ld返回1退出状态Makefile:27:配方目标'bin/greet'失败的原因:*** [bin/greet]错误1

(char const* (*)(), boost::python::default_call_policies const&, boost::mpl::vector1 const&)': /home/eicossa/repo/boost_install/include/boost/python/make_function.hpp:38: undefined reference to boost::python::objects::function_object(boost::python::objects::py_function const&)' /tmp/ccQNpbxG.o: In function boost::python::objects::py_function_impl_base::py_function_impl_base()': /home/eicossa/repo/boost_install/include/boost/python/object/py_function.hpp:20: undefined reference to vtable for boost::python::objects::py_function_impl_base' /tmp/ccQNpbxG.o:(.rodata._ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE[_ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE]+0x30): undefined reference to boost::python::objects::py_function_impl_base::max_arity() const' /tmp/ccQNpbxG.o: In function boost::python::objects::caller_py_function_impl<boost::python::detail::caller<char const* (*)(), boost::python::default_call_policies, boost::mpl::vector1<char const*> > >::~caller_py_function_impl()': /home/eicossa/repo/boost_install/include/boost/python/object/py_function.hpp:30: undefined reference to boost::python::objects::py_function_impl_base::~py_function_impl_base()' /tmp/ccQNpbxG.o:(.rodata._ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE[_ZTIN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE]+0x10): undefined reference to typeinfo for boost::python::objects::py_function_impl_base' /tmp/ccQNpbxG.o: In functionboost::python::converter::expected_pytype_for_arg::get_pytype()': /home/eicossa/repo/boost_install/include/boost/python/converter/pytype_function.hpp:69: undefined reference to boost::python::converter::registry::query(boost::python::type_info)' /home/eicossa/repo/boost_install/include/boost/python/converter/pytype_function.hpp:70: undefined reference to boost::python::converter::registration::expected_from_python_type() const' collect2: error: ld returned 1 exit status Makefile:27: recipe for target 'bin/greet' failed make: *** [bin/greet] Error 1

我在做什么错了?

推荐答案

CXX               := g++
CXX_FLAGS         := -Wall -Wextra -std=c++17 -ggdb

BIN               := bin
SRC               := src
INCLUDE           := inc
LIB               := lib

BOOST_ROOT        := /home/eicossa/repo/boost_install
BOOST_INCL        := ${BOOST_ROOT}/include/
BOOST_LIBS        := ${BOOST_ROOT}/libs/ 

PYTHON_INCL       := /usr/include/python3.7m/
PYTHON_LIBS       := /usr/lib/python3.7/

LIBFLAGS          := -lboost_system  -lboost_python37 -lpython3.7m #changes made here
EXECUTABLE        := greet


all: $(BIN)/$(EXECUTABLE)

run: clean all
        clear
        ./$(BIN)/$(EXECUTABLE)

$(BIN)/$(EXECUTABLE): $(SRC)/*.cpp 
        $(CXX) $(CXX_FLAGS) -I$(PYTHON_INCL) -I$(INCLUDE) -I$(BOOST_INCL) -L$(BOOST_LIBS) -L$(PYTHON_LIBS) -L$(LIB$

clean:
        -rm $(BIN)/*

尝试在Makefile中进行这些更改

Try out these changes in the Makefile

这篇关于编译时将错误与Boost.python链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆