why static library compiled on platform A cannot be used on platform B without warning?

Viewed 94

I'm sorry my English is poor.

I have recently bumped into this.

I have a static library (let's say jsoncpp) compiled on CentOS 7 on x86_64 CPU. And I want to use libjsoncpp.a on Ubuntu 18 04 on x86_64 CPU.

My colleague said it's only related to CPU. But when compiled with the static library, these error message popped up:

Compilation fails with “relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object”
...

and sometimes it's like "this is the wrong PIE object, recompile this with -fPIE".

What I want to know is what factors are in play when using static library compiled on platform A with program compiled on platform B.

Are those factors glibc version and CPU architecture only?

I would appreciate if anyone could point me at some direction.

1 Answers

If the executable is PIC (this is now the default because of ASLR), all of the .o files linked into it (and therefore the .a files) must also be built PIC.

Related