gpt4 book ai didi

c++ - static-libgcc 和 static-libstdc++ 不工作

转载 作者:搜寻专家 更新时间:2023-10-31 02:21:26 29 4
gpt4 key购买 nike

我尝试使用 -static -static-libgcc -static-libstdc++ 编译项目,以便静态链接库。但是,exec 是用动态链接库编译的。我尝试重新安装 gcc 和 g++ 但它没有帮助。这是我本地环境的错误,因为在其他机器上它是静态链接的。

ELF 64-bit LSB  executable, x86-64, version 1 (GNU/Linux), 
dynamically linked (uses shared libs), for GNU/Linux 2.6.24,
BuildID[sha1]=, not stripped

我有 Ubuntu 14.10,gcc 版本 4.8.4

谢谢

最佳答案

我刚刚遇到了同样的问题。我能找到的最好的解释是:

On a side note, your linker could be picking up a dynamic (*.so) library that prevents -static-libstdc++ and -static-libgcc to be used. Every library calling libgcc and libstdc++ should be linked statically (if there is a static version available, of course). https://stackoverflow.com/a/18263911/399105

进一步挖掘,似乎静态链接 glibc(gcc 默认使用)may not be a good idea either ,还有更好的选择,例如 uClibcmusl libc .

在这两者之间,musl 似乎最近得到了维护,所以这就是我的选择。我终于能够通过首先静态构建 musl 来构建一个完全静态的二进制文件:

./configure --disable-shared --enable-wrapper=gcc && make && sudo make install

然后使用 musl 静态构建其他软件:

CC="/usr/local/musl/bin/musl-gcc" LDFLAGS="-static" ./configure

如果你想了解更多细节,你可以看看我在这里做了什么:https://github.com/bmaupin/openldap-tools-static/blob/master/build.sh

关于c++ - static-libgcc 和 static-libstdc++ 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31433592/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com