- 静态和-Static -libstdc++之间的区别在GCC中

发布于 2025-01-21 22:17:04 字数 650 浏览 3 评论 0原文

-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青春如此纠结 2025-01-28 22:17:04

-Static-暗示-Static-Libgcc-static-libstdc ++,以及所有其他库在静态(如果可能的话)上链接到静态上。

您可以看到使用ldd

Linux中的依赖项

$ g++ -static-libstdc++ -static-libgcc test.cpp
$ ldd a.out
        linux-vdso.so.1 (0x00007fff9a7a9000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5122c90000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f5122fb7000)
$ g++ -static test.cpp
$ ldd a.out
        not a dynamic executable

-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

$ g++ -static-libstdc++ -static-libgcc test.cpp
$ ldd a.out
        linux-vdso.so.1 (0x00007fff9a7a9000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5122c90000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f5122fb7000)
$ g++ -static test.cpp
$ ldd a.out
        not a dynamic executable
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文