Is there a way to tell if a binary is linked statically or to a shared library ?
Ans: Yes. Use the utility `ldd’. This gives you information on what libraries are required. If no output is generated when you run `ldd’ on a program then it indicates the program was linked statically. Eg (1): the command (on my linux system) % ldd /bin/init gives no output meaning init was linked statically. And a good thing too it was linked statically 🙂 (NOTE: For programs linked with libc.so.4.5.19 and above, the message “statically linked” will be output in this case). For statically linked ELF executables you will get the message “statically linked (ELF)”. Eg (2): the command (on my linux system) % ldd /usr/bin/gs i.e. the ghostscript interpreter gives the following output. libm.so.4 => /lib/libm.so.4.4 (4.0) libX11.so.3 => /lib/libX11.so.3.0 (DLL Jump 3.0pl0) libc.so.4 => /lib/libc.so.4.4 (DLL Jump 4.3) This tells me that the program `gs’ was dynamically linked and requires three shared libraries. The numbers in brackets tell me that only one library, (libX11), matches the cu