I have created a static library (libar.a
), which contains a function foo
.
I have a shared object (compiled with -fPIC
flag) file that calls foo
.
If the object file containing foo
has a .rodata
section (e.g. a call to printf
or a string literal), trying to compile the shared object with the static library fails with this error:
relocation R_X86_64_32 against '.rodata' can not be used when making a shared object; recompile with -fPIC
/path/to/static/lib/libar.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
I know I can solve it by using -fPIC
to compile my static object, but I try to understand the reason I get this error.
P.S. While looking for it I found that this happens only on 64-bit platforms.
Thanks.