- 静态和-Static -libstdc++之间的区别在GCC中
-Static
添加到最终的二进制输出中,-Static-LibstDC ++
不添加什么其他内容?
我尝试了以下程序:
#include <iostream>
int main( )
{
std::cout << "What does -static do that -static-libstdc++ doesn't do?\n";
}
没有为链接时间指定的任何这些选项,生成的输出仅为 〜17 kb 。但是,通过指定-static-libstdc ++
它变成 〜1.3 Mb 。如果使用-static
,它将变成 〜2.4 Mb 。 static
标志正在添加什么,该标志会导致后两种形式的大小差异很大?如果仅在链接阶段指定-static-libstdc ++
,在运行时可能会影响哪些内容?
现在,如果某人想在Ubuntu(v18.04及以后)构建一个小程序,那么哪一个更合适?
What other stuff does -static
add to the final binary output that -static-libstdc++
does not add?
I checked the excellent answer for this question but it doesn't address this particular question that I have.
I tried the following program:
#include <iostream>
int main( )
{
std::cout << "What does -static do that -static-libstdc++ doesn't do?\n";
}
Without any of these options specified for link-time, the generated output is only ~17 KB. However, by specifying -static-libstdc++
it becomes ~1.3 MB. And if -static
is used instead, it becomes ~2.4 MB. What is being added by the -static
flag that causes the latter two forms to have such a huge difference in size? And which things can be affected at runtime if only the -static-libstdc++
is specified at the linking stage?
Now which one is more suitable if someone wants to build a small program that can be run on Ubuntu (v18.04 and later)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
-Static-
暗示-Static-Libgcc
和-static-libstdc ++
,以及所有其他库在静态(如果可能的话)上链接到静态上。您可以看到使用ldd
Linux中的依赖项
-static-
implies-static-libgcc
and-static-libstdc++
as well as that all other libraries are linked in, if possible, statically.You can see what doesn't get in using ldd
Dependency resolution in Linux