I've a program which links to many libraries. g++, by default, prefers to link to shared libraries , even if corresponding archive exists. How can I change this preference to prefer static archive over dynamic libraries , if a static archive exists. Note , I used '-static' option, but it tries to find static archive for all libraries which is not what I want.
+3
A:
g++ -Wl,-Bstatic -lz -lfoo -Wl,-Bdynamic -lbar -Wl,--as-needed
Will link zlib and libfoo as static, and libbar as dynamic . --as-needed will drop any unused dynamic library
naideflan
2010-09-13 14:00:06