<i id='x4ahP'><tr id='x4ahP'><dt id='x4ahP'><q id='x4ahP'><span id='x4ahP'><b id='x4ahP'><form id='x4ahP'><ins id='x4ahP'></ins><ul id='x4ahP'></ul><sub id='x4ahP'></sub></form><legend id='x4ahP'></legend><bdo id='x4ahP'><pre id='x4ahP'><center id='x4ahP'></center></pre></bdo></b><th id='x4ahP'></th></span></q></dt></tr></i><div id='x4ahP'><tfoot id='x4ahP'></tfoot><dl id='x4ahP'><fieldset id='x4ahP'></fieldset></dl></div>

      <legend id='x4ahP'><style id='x4ahP'><dir id='x4ahP'><q id='x4ahP'></q></dir></style></legend><tfoot id='x4ahP'></tfoot>

      1. <small id='x4ahP'></small><noframes id='x4ahP'>

          <bdo id='x4ahP'></bdo><ul id='x4ahP'></ul>
      2. 使用 -static-libgcc -static-libstdc++ 编译仍然会导致对

        时间:2023-09-18
        <legend id='vDxHB'><style id='vDxHB'><dir id='vDxHB'><q id='vDxHB'></q></dir></style></legend>
        <tfoot id='vDxHB'></tfoot>

            <tbody id='vDxHB'></tbody>
          <i id='vDxHB'><tr id='vDxHB'><dt id='vDxHB'><q id='vDxHB'><span id='vDxHB'><b id='vDxHB'><form id='vDxHB'><ins id='vDxHB'></ins><ul id='vDxHB'></ul><sub id='vDxHB'></sub></form><legend id='vDxHB'></legend><bdo id='vDxHB'><pre id='vDxHB'><center id='vDxHB'></center></pre></bdo></b><th id='vDxHB'></th></span></q></dt></tr></i><div id='vDxHB'><tfoot id='vDxHB'></tfoot><dl id='vDxHB'><fieldset id='vDxHB'></fieldset></dl></div>
                • <bdo id='vDxHB'></bdo><ul id='vDxHB'></ul>

                • <small id='vDxHB'></small><noframes id='vDxHB'>

                  本文介绍了使用 -static-libgcc -static-libstdc++ 编译仍然会导致对 libc.so 的动态依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试制作一个尽可能可移植的可执行文件.删除一些依赖项后,我在另一个系统上运行二进制文件时遇到了以下问题:

                  I'm trying to make an executable that's as portable as possible. After removing a few dependencies, I came across the following when running the binary on another system:

                  /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.15' not found (required by foob)
                  /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.15' not found (required by foob)
                  /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by foob)
                  

                  我希望我的二进制文件不要求用户升级他们的 libc 版本,所以我也想删除这个依赖项.

                  I'd prefer my binary not to require the user to upgrade their version of libc, so I'd like to remove this dependency as well.

                  生成上述二进制文件的链接器标志已经包含 -static-libgcc -static-libstdc++.为什么二进制文件仍然需要共享的 libc.so.6?

                  The linker flags that produced the above binary already included -static-libgcc -static-libstdc++. How come the binary still requires on the shared libc.so.6?

                  我也尝试添加 -static 标志,但是当我尝试运行 那个 二进制文件时,结果很奇怪:

                  I tried adding the -static flag as well, however when I try to run that binary the result is very strange:

                  $ ls -l foob
                  -rwxr-xr-x 1 claudiu claudiu 13278191 Oct 10 13:03 foob
                  $ ./foob
                  bash: ./foob: No such file or directory
                  

                  怎么办?

                  $ file foob
                  foob: ELF 64-bit LSB  executable, x86-64, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=5adee9a598b9261a29f1c7b0ffdadcfc72197cd7, not stripped
                  $ strace -f ./foob
                  execve("./foob", ["./foob"], [/* 64 vars */]) = -1 ENOENT (No such file or directory)
                  write(2, "strace: exec: No such file or di"..., 40strace: exec: No such file or directory
                  ) = 40
                  exit_group(1)                           = ?
                  +++ exited with 1 +++
                  

                  有趣的是,如果我ldd没有-static的版本,它比版本两个条目使用 -static,即:

                  Interestingly, if I ldd the version without -static, it has two less entries than the version with -static, namely:

                  libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f4f420c1000)
                  libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4f41636000)
                  

                  推荐答案

                  GNU libc 并非设计为静态链接.重要功能,例如gethostbynameiconv 在静态二进制文件中会出现故障或根本无法工作.可以说更糟糕的是,在某些情况下,静态二进制文件会尝试动态打开和使用 libc.so.6,即使静态链接的全部目的是避免这种依赖关系.

                  GNU libc is not designed to be statically linked. Important functions, e.g. gethostbyname and iconv, will malfunction or not work at all in a static binary. Arguably even worse, under some conditions a static binary will attempt to dynamically open and use libc.so.6, even though the whole point of static linkage is to avoid such dependencies.

                  您应该针对 uClibc 或 musl libc 代替.

                  You should compile your program against uClibc or musl libc instead.

                  (至少 15 年来一直如此.)

                  (This has been true for at least 15 years.)

                  这篇关于使用 -static-libgcc -static-libstdc++ 编译仍然会导致对 libc.so 的动态依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:从 MinGW 链接到 MSVC DLL 下一篇:C++:何时(以及如何)调用 C++ 全局静态构造函数?

                  相关文章

                  最新文章

                  <small id='aw0vm'></small><noframes id='aw0vm'>

                    <i id='aw0vm'><tr id='aw0vm'><dt id='aw0vm'><q id='aw0vm'><span id='aw0vm'><b id='aw0vm'><form id='aw0vm'><ins id='aw0vm'></ins><ul id='aw0vm'></ul><sub id='aw0vm'></sub></form><legend id='aw0vm'></legend><bdo id='aw0vm'><pre id='aw0vm'><center id='aw0vm'></center></pre></bdo></b><th id='aw0vm'></th></span></q></dt></tr></i><div id='aw0vm'><tfoot id='aw0vm'></tfoot><dl id='aw0vm'><fieldset id='aw0vm'></fieldset></dl></div>

                        <bdo id='aw0vm'></bdo><ul id='aw0vm'></ul>
                      <legend id='aw0vm'><style id='aw0vm'><dir id='aw0vm'><q id='aw0vm'></q></dir></style></legend>
                      <tfoot id='aw0vm'></tfoot>