I’m trying to link with the static libc.a and a dynamic lib .so unsuccessfully.
I’ve already tryied the following:
-
Firstly I test with all dynamic:
- gcc -shared libtest.c -o libtest.so
- gcc -c main.c -o main.o
- gcc main.o -o test -L. -ltest
It’s working (compile and execute)
-
Secondly I test what I want (dynamic lib and static libc) :
- gcc -shared libtest.c -o libtest.so
- gcc -c main.c -o main.o
- gcc main.o -o test libtest.so /usr/lib/libc.a
It’s compiling, but at execution, it segfault!
A strace show that it’s trying to access libc.so!!! -
Finally I’ve tried to compile a simple progam with no reference to dynamic lib
- gcc -static main.c –> compile ok, run ok
- gcc main.c /usr/lib/libc.a –> compile ok, run : segmentation fault (a strace show that it’s access to libc.so)
How to do that?
Thank you
Your second test (the one you want to do) is working for me on i686-linux:
However, you have to realise that the shared library you’ve build depends on the shared libc. So, it’s natural that it’s trying to open it at runtime.
One way to achieve what you want is to use:
-static-libgcc -Wl,-Bstatic -lc.