2011-03-09 49 views
3

我是用boost.python庫構建的應用程序。我想鏈接它。下面是代碼:Ld錯誤符號

#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 

什麼是錯的呢?

回答

1

你有-fPIC.o的目標,但不是 爲.so目標。看看是否添加它有幫助。

編輯:忽略這一點。這爲我編譯使用Python 2.6和Boost 1.44的32位Ubuntu系統。正如Ignacio Vazquez-Abrams指出的,您應該檢查您的Python和Boost庫是否爲相同的體系結構編譯。

相關問題