3

I'm trying to create a shared library on centos using gcc 4.8.2

shared library code:

//reload.c
int func(int num){
    return num++;
}

link command:

gcc -fPIC -shared reload.c -o reload.so

use ldd command:

linux-vdso.so.1 =>  (0x00007ffe6aa93000)
libc.so.6 => /usr/lib64/libc.so.6 (0x00007f27feb97000)
/lib64/ld-linux-x86-64.so.2 (0x00007f27ff169000)

Now, Want to statically link glibc, how to write it?

like it:

ldd xxx.so
    not a dynamic executable

I tried the build options, but the error.

gcc -fPIC -shared reload.c -o reload.so -Wl,-Bstatic -lc
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status

thank you very much

1

1 Answer 1

2

You do not have dependencies to glibc at all for your code above, so the easiest way is to compile with the flag -nostdlib:

$ gcc -fPIC -shared reload.c -o reload.so -nostdlib
$ ldd reload.so
statically linked
Sign up to request clarification or add additional context in comments.

Comments

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.