16

I need to statically link glibc to my project, because the target platform supports only a very old one ( but it works with statically linked glibc from my toolchain, I have checked it)

Unfortunately, this application has to make use of pthread library, but statically linked libpthread takes too much space.

I would like to statically link glibc, and dynamically pthread.

After running this command

powerpc-unknown-linux-gnu-gcc object_files -lrt -lpthread -Wl,-Bstatic -lc 

I get:

/powerpc-unknown-linux-gnu/bin/ld: cannot find -lgcc_s
101010
  • 14,866
  • 30
  • 95
  • 172
nkdm
  • 1,220
  • 1
  • 11
  • 26

2 Answers2

11

There is a -static-libgcc if that may help

Anycorn
  • 50,217
  • 42
  • 167
  • 261
  • 1
    @nkdm then you need to go with R..'s suggestion of uclibc – Anycorn Nov 03 '12 at 18:27
  • 16
    For the record libgcc is not glibc (which is what the title of this SO question is about). glibc is the GNU implementation of the C standard library. libgcc is part of the gcc internals and is used by gcc "whenever it needs to perform some operation that is too complicated to emit inline code for". – Doug Richardson May 23 '14 at 20:40
  • Why is this answer accepted since it's completely wrong? – drizzt Jun 01 '23 at 22:49
9

You should be using -static, not -Wl,-static. The latter bypasses gcc's knowledge, and therefore gcc is still trying to link the shared libgcc_s.so rather than the static libgcc_eh.a.

If your aim is to link libc statically but libpthread dynamically, this is simply not going to work. You cannot mix and match different versions of libpthread; it's part of glibc, just a separate file, and the internals need to match. Even with the same version, I think linking libc statically and libpthread dynamically will be very broken.

If glibc is too big for your needs, you could try an alternate libc like uClibc or musl.

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • But I need to have lpthread linked dynamically. The -static option will link everything statically. – nkdm Nov 02 '12 at 00:33