Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Statically linking libraries in linux [duplicate]

Tags:

c

linux

gcc

I have an application which links to a number of libraries, most of them are available as both static as well as dynamic library on my machine. Below 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 library but as per the gcc documentation, by default it links every library dynamically. What is the method to tell gcc to link a specific library statically even its dynamic version is also available on the system?

like image 824
Ravi Gupta Avatar asked Jan 28 '26 06:01

Ravi Gupta


1 Answers

gcc has a -static flag.

like image 130
facha Avatar answered Jan 29 '26 18:01

facha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!