我正在使用 boost.python 库构建应用程序。我想要进行链接操作。以下是代码:
有什么问题吗?
#include <boost/python.hpp>
using namespace boost::python;
// Boost.python definitions to expose classes to Python
BOOST_PYTHON_MODULE(arrayClasses) {
}
并且为此编写makefile:
PYTHON = /usr/include/python2.7
BOOST_INC = /usr/include
BOOST_LIB = /usr/lib
TARGET = arrayClasses
$(TARGET).so: $(TARGET).o
g++ -shared -Wl,--export-dynamic \
$(TARGET).o -L$(BOOST_LIB) -lboost_python \
-L/usr/lib/python2.7/config -lpython2.7 \
-o $(TARGET).so
$(TARGET).o: $(TARGET).cpp
g++ -I$(PYTHON) -I$(BOOST_INC) -c -fPIC $(TARGET).cpp
当我编译它时,会出现以下错误:
g++ -shared -Wl,--export-dynamic \
arrayClasses.o -L/usr/lib -lboost_python \
-L/usr/lib/python2.7/config -lpython2.7 \
-o arrayClasses.so
/usr/bin/ld: arrayClasses.o: relocation R_X86_64_32 against `init_module_arrayClasses()' can not be used when making a shared object; recompile with -fPIC
arrayClasses.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
有什么问题吗?