Glibc的静态链接 [英] Static linking of Glibc

查看:429
本文介绍了Glibc的静态链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何编译静态链接glibc库的应用程序,而仅编译应用程序所需的代码? (不是全部lib)

How can i compile my app linking statically glibc library, but only the code needed for my app? (Not all lib)

现在我的编译命令:

g++  -o newserver  test.cpp ... -lboost_system -lboost_thread -std=c++0x

谢谢!

推荐答案

这就是 -static 的作用(如另一个答案所述) ):不需要的模块不会链接到您的程序中。但是您对所需数量的期望(从某种意义上说,我们不能说服连接器相反)可能太乐观了。

That's what -static does (as described in another answer): unneeded modules won't get linked into your program. But your expectations on the amount of stuff which is needed (in a sense that we can't convince linker to the contrary) may be too optimistic.

如果您尝试这样做是为了可移植性(在具有较旧glibc或类似功能的其他计算机上运行可执行文件),则存在一个简单的测试问题,以查看您是否会获得想要的东西:

If you trying to do it for portability (running an executable on other machines with older glibc or something like that), there is one easy test question to see if you're going to get what you want:

您是否想到了 libnss 的问题,您确定它不会咬你吗?

Did you think of the problem with libnss, and are you sure it is not going to bite you?

如果您的回答是,也许继续这样做是有意义的。如果答案是否定的,或者问题似乎太晦涩,没有答案,只需使用静态链接的glibc退出到期日:受到伤害的机会多于帮助。

If your answer is yes, maybe it makes sense to go on. If the answer is no, or the question seems too obscure and there is no answer, just quit your expirements with statically linked glibc: it has more chance to hurt than help.

这篇关于Glibc的静态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆