3

I'm buildnig application with boost.python library. I want to link it. 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 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's wrong is there?

1 Answer 1

1

You have -fPIC for your .o target, but not for the .so target. See if adding it helps.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.