0

I am currently building a shared library (lib1.so) out of a cmake environment. lib1.so depends on an external static lib libLASlib.a (which I am able to recompile if necessary). Everything works wonder on windows so far, but it's another story when switching to linux:

/usr/bin/ld: lib/LASlib/libLASlib.a(lasreader.cpp.o): relocation R_X86_64_PC32 against symbol `_ZN9LASreader35read_point_filtered_and_transformedEv' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value

So I tried recompiling the libLASlib with -fPIC -> same error

Due to my environment I could not verify the fpic was effectivelly added to the gcc command line.

Here is what I tried to confirm there was no issue with the fPIC:

readelf --dynamic libLASlib.a | grep lasreader.cpp.o -A2
File: libLASlib.a(lasreader.cpp.o)

There is no dynamic section in this file.

For the record not a single cpp.o was found with a dynamic section

I have tried just to see what it would give if i changed liblas from a static to a shared library -> no error

Any thoughs? Many thanks!

Pascal M
  • 1
  • 1

2 Answers2

0

You need to compile lasreader.cpp with -fPIC. Something like this:

g++ -c -fPIC -o lasreader.cpp.o lasreader.cpp

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • As said, I have compîled the whole libLASlib.a with -fPIC (lasreader.cpp being part of it) If I am not mistaking, "File: libLASlib.a(lasreader.cpp.o) There is no dynamic section in this file." Should mean there is no issue about the PIC flag right? – Pascal M Aug 30 '19 at 13:34
  • Compile it manually like I showed and then create the lib using the object file manually to verify that it's not your cmake setup that is causing problems. Whenever I've gotten that error, the object file was not created using fPIC – Ted Lyngmo Aug 30 '19 at 14:08
  • Thx for pointing it out, the fPIC was indeed not applied (conan doesn't seem to forward the fPIC option) I edited the CMAKELIST and added "set_property(TARGET LASlib PROPERTY POSITION_INDEPENDENT_CODE ON)" -----> that worked for me Can't upvote your answer as I'm a recent user on this site sorry :/ – Pascal M Aug 30 '19 at 15:23
0

The fPIC was indeed not applied

Conan doesn't seem to forward the fPIC option

I edited the CMAKELIST and added

set_property(TARGET LASlib PROPERTY POSITION_INDEPENDENT_CODE ON)

And it eventualy passed

Pascal M
  • 1
  • 1