Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ld wrong symbol

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?

like image 407
Max Frai Avatar asked Jun 29 '26 14:06

Max Frai


1 Answers

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.

like image 86
phooji Avatar answered Jul 01 '26 02:07

phooji