我正在尝试使用 boost.python 构建一个简单的程序。
我有以下代码:
//greet.cpp
#include <iostream>
#include <boost/python.hpp>
void greet()
{
std::cout << "hello world!" << std::endl;
}
BOOST_PYTHON_MODULE(greet)
{
using namespace boost::python;
def("greet", greet);
}
和以下makefile
:
PYTHON_VERSION := 2.7
PYTHON_INC := /usr/include/python$(PYTHON_VERSION)
PYTHON_LIB_LOCATION := /usr/lib/python${PYTHON_VERSION}
PYTHON_LIB_FILE := python${PYTHON_VERSION}
BOOST_INC := ~/boost_1_54_0
BOOST_LIB_LOCATION := /home/elyashiv/boost_1_54_0/stage/lib
BOOST_LIB_FILE := boost_python
CC := gcc
CFLAGS := -c -fPIC
CInc := -I ${BOOST_INC} -I ${PYTHON_INC}
CLinkFlags = -shared -Wl,-soname,$@ -L${BOOST_LIB_LOCATION} -l${BOOST_LIB_FILE} -L${PYTHON_LIB_LOCATION} -l${PYTHON_LIB_FILE}
greet.o: greet.cpp
%.so: %.o
gcc ${CLinkFlags} -o $@ $^
%.o: %.cpp
${CC} ${CFLAGS} ${CInc} $^
runningmake greet.so
运行时只出现一些警告(在某些 boost 文件中重新定义)。
当我尝试在 python 中导入模块时,我得到以下信息:
Python 2.7.3 (default, Apr 10 2013, 05:46:21)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import greet
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: ./greet.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv
我做错了什么以及如何解决?
编辑
的输出ldd greet.so
:
linux-gate.so.1 => (0x001ee000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0x0055d000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x0058e000)
/lib/ld-linux.so.2 (0x003a2000)