3

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?

Ravi Gupta
  • 6,258
  • 17
  • 56
  • 79
  • http://stackoverflow.com/questions/809794/use-both-static-and-dynamically-linked-libraries-in-gcc answers this question – Habbie Oct 06 '10 at 07:11

1 Answers1

4

gcc has a -static flag.

facha
  • 11,862
  • 14
  • 59
  • 82
  • but it will force all libraries to link statically. I want to link some libraries statically and some dynamically. – Ravi Gupta Oct 06 '10 at 07:09
  • 3
    -static keyword will enforce linking libraries that come after it statically linked. and samewise for the -dynamic flag. this way you can specify which ones to link dynamically and which ones to link statically. – rgngl Oct 06 '10 at 07:55
  • @bad zeppelin: Could you give us an example please? – jyz Oct 06 '10 at 11:14
  • gcc a.o b.o ... z.o -Wl,-B,static -lfoo -Wl,-B,dynamic -lbar – rgngl Oct 06 '10 at 14:33
  • If you want to link some libraries statically and some dynamically then few years ago - It was only one solution for such case - rename your static libraries.... – Konstantin Burlachenko Oct 03 '14 at 08:54