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

3

8

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?

Colpitis answered 15/8, 2017 at 11:18 Comment(2)
Just wondering, what is this Cross C++ linker? Is it for cross-compilation?Vulcanize
@Vulcanize I'm not really sure what it is exactly. I was referring to a ledger in the CDT IDE, which is the C++ flavor of EclipseColpitis
D
2

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.

Disappear answered 9/12, 2021 at 20:36 Comment(2)
Could you add some reference to the flags to enable PIC eg in CMAKE and/or other common kind of makefiles? ThanksHermineherminia
For CMake it is easy. For other build systems I am not 100% sure, but basically you have to extend the CFLAGS and/or CXXFLAGS with the -fPIC option. For unix makefiles, it looks like something similar to this.Iminourea
L
1

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

Luzern answered 12/9, 2019 at 9:3 Comment(0)
C
0

I had to recompile, but it sufficed to recompile as *.a library again. I'm pretty sure the problem originated from an update of my gcc compiler.

Colpitis answered 26/8, 2017 at 13:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.