-1

To link gcc statically into a shared library, based on the answer in this question, the remaining problem is how to let the linker use the PIC version of libc.a instead of the non-PIC version. The problem is the same as that answer:

g++ -fPIC -Wall -O0 -fexceptions -g -c main.cpp -o main.o
ld -shared -static -o test.so main.o -lc
ld: //usr/lib/x86_64-linux-gnu/libc.a(malloc.o): relocation R_X86_64_TPOFF32 against `tcache' can not be used when making a shared object; recompile with -fPIC

This is what I'v tried:

sudo apt-get install libc-pic //then libc6-pic get installed successfully
ld -shared -static -o test.so main.o -lc //same as above, same error
ld -shared -static -o test.so main.o -lc-pic //not working: cannot find -lc-pic
ld -shared -static -o test.so main.o -lc6-pic //not working: cannot find -lc6-pic
jw_
  • 1,663
  • 18
  • 32

1 Answers1

1

Looking at the list of files in the package there is a libc_pic.a so the correct option seems to be -lc_pic.

  • There are new problem: ld: test.so: version node not found for symbol pthread_cond_wait@@GLIBC_2.3.2 ld: failed to set dynamic section sizes: Bad value. Do you happen to know the answer too? – jw_ Apr 23 '21 at 09:52
  • 1
    @jw_ https://stackoverflow.com/a/41816199/14215102 <- I think that's what the .map files in the file list are for? –  Apr 23 '21 at 10:00
  • @jw_, have you succeeded with this? Looks like the symbol versioning is broken for many functions, not just this one. Moreover, I even don't understand where pthread_cond_wait is coming from, because I don't have a dependency on it! – Dmitry Mikushin May 27 '23 at 01:01