Invalid Ld character

I am creating an application with boost.python library. I want to tie him up. Here is the code:

#include <boost/python.hpp>
using namespace boost::python;

// Boost.python definitions to expose classes to Python
BOOST_PYTHON_MODULE(arrayClasses) {
}

And the makefile for it:

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

When I compile it, I get:

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

What is wrong there?

+3
source share
1 answer

You have it -fPICfor your purpose .o, but not for the purpose .so. See if the addition helps.

Edit: Ignore this. This compiles for me on a 32-bit Ubuntu system using Python 2.6 and Boost 1.44. As Ignacio Vasquez-Abrams noted, you should check if your Python and Boost libraries were compiled for the same architecture.

+1
source

All Articles