我正在尝试构建受这里启发的示例
我的初衷是能够从Python内部调用C++代码。为了实现这个目标,我只是运行Boost文档中的示例。
这是我的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:在函数
PyInit_hello_ext': /home/eicossa/Dropbox/wtcd/license/boost/src/bindings.cpp:3: undefined reference toboost::python::detail::init_module(PyModuleDef&,中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:void ()()‘/tmp/ccQNpbxG.o:函数boost::python::type_info::name() const': /home/eicossa/repo/boost_install/include/boost/python/type_id.hpp:160: undefined reference to__boost::python::detail::gcc_demangle(char const)’/tmp/ccQNppbxG.o:函数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 toboost::python::converter::do_return_to_python(char const* )/tmp/ccQNppbxG.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: undefined reference toPyUnicode_Type‘/tmp/ccQNppbxG.o:在函数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*)‘/tmp/ccQNpbxG.o:函数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: undefined reference toboost::python::objects::function_object(boost::python::objects::py_function const&)’/tmp/ccQNpbxG.o: boost::python::objects::py_function_impl_base‘/tmp/ccQNpbxG.o:(.rodata._ZTVN5boost6python7objects23caller_py_function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE_ZTVN5boost6python7objects23caller_py_函数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 tovtable中function_implINS0_6detail6callerIPFPKcvENS0_21default_call_policiesENS_3mpl7vector1IS6_EEEEEE+0x30):未定义引用toboost::python::objects::py\_function\_impl\_base::max\_arity() const' /tmp/ccQNpbxG.o: In functionboost::python::objects::caller_py_function_implboost::python::converter::expected\_pytype\_for\_arg::get\_pytype()': /home/eicossa/repo/boost\_install/include/boost/python/converter/pytype\_function.hpp:69: undefined reference toboost::python::converter::registry::query(boost::python::type_info的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类型信息的未定义引用)‘/home/eicossa/repo/boost_install/include/boost/python/converter/pytype_function.hpp:70:未定义的对’boost::python::converter::registration::expected_from_python_type() const‘collect2的引用:错误: ld返回一个退出状态Makefile:27:目标' bin/greet’失败的配方:*bin/greet错误1
我做错什么了?
发布于 2019-10-21 07:45:28
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中尝试这些更改
https://stackoverflow.com/questions/58481872
复制相似问题