Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CDT using lib*.a --- relocation R_X86_64_32S against symbol ... can not be used

I try to reference a static *.a library for my c++ project in CDT. I included it in

C/C++ Build -> Cross C++ Linker -> Libraries

But I get the error:

relocation R_X86_64_32S against symbol ... can not be used when making a shared object.

Now from what I have read so far I think this means the compiler thinks I am referencing a shared library, when it is a static library instead - Is that the case and if so what can do now? Is there any way to just use the *.a libraries or do I have to recompile them as .so - objects?

like image 857
don-joe Avatar asked Aug 15 '17 11:08

don-joe


2 Answers

The problem is most probably coming from the fact that the static library is compiled without supporting position independent code. I don't know a way to fix it without recompiling the static library.

If you can recompile the static library, then assuming you are using gcc or clang, you have to add the -fPIC flag to your compiler flags.

Without more information it is hard to give more advice. If you can provide a minimal, reproducible example, then I can help you with that.

like image 57
János Benjamin Antal Avatar answered Oct 23 '22 16:10

János Benjamin Antal


In my case, I had just compiled it as *.a, so I was pretty sure a recompile again as *.a wouldn't work, there was no chance gcc was updated in the meantime. So I tried what you mentioned in the question already: removed the .a libs and recompiled&installed as .so and it worked. Thanks :D

like image 21
N4ppeL Avatar answered Oct 23 '22 16:10

N4ppeL