我正在尝试使用boost::python
(通过自制程序安装)创建一个共享对象,该对象可以在操作系统附带的python2.7的osx上的Python中加载。我需要链接哪些库才能获得可用的共享对象?在
这是hello_ext.cpp
,取自教程
// hello_ext.cpp
char const* greet() {
return "hello, world";
}
#include <boost/python.hpp>
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
我可以像这样编译这个示例,尽管这需要一段时间。在
^{pr2}$但是,当我试图链接它并生成一个so
时,我得到了一堆未定义的符号:
$ clang++ -shared -o hello_ext.so hello_ext.o | & head -n 7
Undefined symbols for architecture x86_64:
"_PyString_Type", referenced from:
boost::python::to_python_value<char const* const&>::get_pytype() const in hello_ext.o
"__Py_NoneStruct", referenced from:
boost::python::api::object::object() in hello_ext.o
"boost::python::detail::init_module(char const*, void (*)())", referenced from:
_inithello_ext in hello_ext.o
其中一些显然来自Python解释器,实际上{
$ clang++ -shared -o hello_ext.so hello_ext.o -lpython | & head -n 7
Undefined symbols for architecture x86_64:
"boost::python::detail::init_module(char const*, void (*)())", referenced from:
_inithello_ext in hello_ext.o
"boost::python::detail::gcc_demangle(char const*)", referenced from:
boost::python::type_info::name() const in hello_ext.o
"boost::python::detail::scope_setattr_doc(char const*, boost::python::api::object const&, char const*)", referenced from:
void boost::python::def<char const* (*)()>(char const*, char const* (*)()) in hello_ext.o
关于boost::python
的文档here详细介绍了如何与cmake
一起使用该库,但没有详细说明在链接时需要哪些库。在
boost::python
不是只包含头的库,它包含一个二进制组件。例如,你需要和它联系起来该库显然是由自制程序包}。在
boost-python
安装的,而不是{相关问题 更多 >
编程相关推荐