因为我没有root权限,所以我从本地通过以下方式安装了Boost.Python
:
$ export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/export/home/me/anaconda3/include/python3.6m
$ ./bootstrap.sh --prefix=/export/home/me/Opt/boostpython --without-icu --with-python=/export/home/me/anaconda3/bin/python3.6 --with-libraries=system,thread,python --with-python-root=/export/home/me/anaconda3 --with-python-version=3.6
$ ./b2 && ./b2 install
然后在/export/home/me/Opt/boostpython/lib
中,我建立了一个软链接
$ ln -s libboost_python36.so.1.67.0 libboost_python3.so
Makefile
是
PYTHON_VERSION = 3.6
PYTHON_HOME_PATH = /export/home/me/anaconda3/
PYTHON_INCLUDE = $(PYTHON_HOME_PATH)/include/
BOOST_INC = /export/home/me/Opt/boostpython/include/boost/
BOOST_LIB = /export/home/me/Opt/boostpython/lib/
BOOST_PYTHON_LIB = /export/home/me/Opt/boostpython/lib/
TARGET = main
EXTEND_FILE = main_ext
$(TARGET).so:$(TARGET).o
g++ -shared depend.o -L$(BOOST_LIB) -L$(BOOST_PYTHON_LIB) -lboost_python3 `/export/home/me/anaconda3/bin/python3.6m-config --libs --ldflags` -o depend_ext.so
g++ -shared depend.o $(TARGET).o -L$(BOOST_LIB) -L$(BOOST_PYTHON_LIB) -lboost_python3 `/export/home/me/anaconda3/bin/python3.6m-config --libs --ldflags` -o $(TARGET).so
mv $(TARGET).so $(EXTEND_FILE).so
depend.o:depend.cpp
g++ `/export/home/me/anaconda3/bin/python3.6m-config --includes` -fPIC -c depend.cpp -O3 -std=c++11
$(TARGET).o:$(TARGET).cpp
g++ `/export/home/me/anaconda3/bin/python3.6m-config --includes` -fPIC -c depend.cpp $(TARGET).cpp -O3 -std=c++11
clean:
rm *.so *.o *.gch
但是当make
时,我收到了错误消息
g++ -shared depend.o -I/export/home/me/Opt/boostpython/include/boost/ -L/export/home/me/Opt/boostpython/lib/ -L/export/home/me/Opt/boostpython/lib/ -lboost_python3 `/export/home/me/anaconda3/bin/python3.6m-config --libs --ldflags` -o depend_ext.so
/usr/bin/ld: /export/home/me/anaconda3/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6m.a(abstract.o): unrecognized relocation (0x2a) in section `.text'
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
make: *** [main.so] Error 1
我得到了main.o
和depend.o
,该错误发生在链接阶段。我该如何解决?