C – Statically linked libraries in linux

Statically linked libraries in linux… here is a solution to the problem.

Statically linked libraries in linux

I have an application that links to many libraries, most of which are available on my machine as both static and dynamic libraries. The following is the output of the ldd command.

linux-gate.so.1 =>  (0xffffe000)
libssl.so.0.9.8 => /usr/lib/libssl.so.0.9.8 (0xb782c000)
libc.so.6 => /lib/libc.so.6 (0xb76cc000)
libcrypto.so.0.9.8 => /usr/lib/libcrypto.so.0.9.8 (0xb755a000)
/lib/ld-linux.so.2 (0xb788d000)
libdl.so.2 => /lib/libdl.so.2 (0xb7555000)
libz.so.1 => /lib/libz.so.1 (0xb7540000)

I want to statically link libssl libraries, but according to the gcc documentation, it dynamically links each library by default. What is the way to tell gcc to statically link a particular library, even if a dynamic version of it is available on the system?

Related Problems and Solutions