1
votes

when compiling shared library which links boost and python libraries I receive error:

/usr/bin/ld: libboost_python.a(from_python.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC libboost_python.a: could not read symbols: Bad value

I've used verbose mode to look at compiler definitions:

/usr/bin/c++ -fPIC -g -shared -Wl,-soname,libCore.so -o .../libCore.so Core.cpp.o -lpython2.7 -Wl,-Bstatic -lboost_python -Wl,-Bdynamic

That's it! I have to remove -Wl, -Bstatic from definitions but how to do that? I'm using cmake build system and here is a part of code which generates that shared library:

set(Core_SRC
    Core.cpp
)
add_definitions(-g -fPIC)
add_library(Core SHARED ${Core_SRC})

target_link_libraries(Core
    ${PYTHON_LIBRARIES}
    ${Boost_LIBRARIES}
)
1

1 Answers

0
votes

The problem is you're trying to build a shared library with libboost_python which appears to have been built in such a way that it can't be linked into a shared library.

There's 3 ways round that.

  1. Don't make your library shared
  2. Build a shared version of the boost_python library
  3. eave the references to boost_python unresolved