Telling gcc directly to link a library statically

Elazar Leibovich picture Elazar Leibovich · Jul 5, 2011 · Viewed 197k times · Source

It feels strange to me to use -Wl,-Bstatic in order to tell gcc which libraries I want to link with statically. After all I'm telling gcc directly all other information about linking with libraries (-Ldir, -llibname).

Is it possible to tell the gcc driver directly which libraries should be linked statically?

Clarification: I know that if a certain library exists only in static versions it'll use it without -Wl,-Bstatic, but I want to imply gcc to prefer the static library. I also know that specifying the library file directly would link with it, but I prefer to keep the semantic for including static and dynamic libraries the same.

Answer

Radek picture Radek · Dec 22, 2013

It is possible of course, use -l: instead of -l. For example -l:libXYZ.a to link with libXYZ.a. Notice the lib written out, as opposed to -lXYZ which would auto expand to libXYZ.