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

bob.smart
  • 35
  • 1
  • 7

1 Answers1

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
Ctx
  • 18,090
  • 24
  • 36
  • 51