static linking only some libraries

peoro picture peoro · Nov 11, 2010 · Viewed 155.4k times · Source

How can I statically link only a some specific libraries to my binary when linking with GCC?

gcc ... -static ... tries to statically link all the linked libraries, but I haven't got the static version of some of them (eg: libX11).

Answer

Šimon Tóth picture Šimon Tóth · Nov 11, 2010

gcc -lsome_dynamic_lib code.c some_static_lib.a