Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've a program which links to many libraries. g++, by default, prefers to link to shared libraries, even if the corresponding archive exists.

How can I change this preference to prefer static archives 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
718 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...