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
3
  • You'll need to add -Wl,-Bdynamic after the -lc. Commented Nov 2, 2012 at 0:24
  • Oh, I'm sorry it was my mistake. I wanted to link glibc statically Commented Nov 2, 2012 at 0:29
  • Related: stackoverflow.com/questions/809794/… Commented May 5, 2015 at 18:31

2 Answers 2

11

There is a -static-libgcc if that may help

Sign up to request clarification or add additional context in comments.

3 Comments

@nkdm then you need to go with R..'s suggestion of uclibc
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".
Why is this answer accepted since it's completely wrong?
10

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.

1 Comment

But I need to have lpthread linked dynamically. The -static option will link everything statically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.