G ++链接:强制静态链接,如果静态库的存在? [英] g++ linker: force static linking if static library exists?
本文介绍了G ++链接:强制静态链接,如果静态库的存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个程序,它链接到许多图书馆。 G ++,默认情况下,prefers链接到共享库,即使相应的档案存在。我怎样才能改变这种preference至preFER静态归档了动态库,如果静态档案的存在。请注意,我用'-static'选项,但它试图找到静态存档所有库这不是我想要的。
解决方案
G ++ -Wl,-Bstatic -lfoo -lz轮候册,-Bdynamic -lbar轮候册, - AS-需要
将链接的zlib
和 libfoo的
静态和 libbar的
动态。 - 按需
将删除未使用的动态库
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.
解决方案
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.
这篇关于G ++链接:强制静态链接,如果静态库的存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文