为什么不可能完全静态地链接应用程序? [英] Why would it be impossible to fully statically link an application?
问题描述
我正在尝试使用GCC编译静态链接的二进制文件,并且收到如下警告消息:
I'm trying to compile a statically linked binary with GCC and I'm getting warning messages like:
warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
我什至不知道getwnam_r
的作用,但是我认为它是从更高级别的API内部调用的.我收到gethostbyname
的类似消息.
I don't even know what getwnam_r
does, but I assume it's getting called from inside some higher level API. I receive a similar message for gethostbyname
.
为什么不能像其他所有功能一样仅静态链接这些功能?
Why would it not be possible to just statically link these functions in like every other function?
推荐答案
需要访问NSS的函数调用或iconv需要访问权限将动态打开其他库,因为NSS需要插件才能正常工作(帮助程序模块,例如pam_unix.so).当NSS系统dl打开这些模块时,将有两个冲突的glibc版本-一个程序附带的glibc(静态编译),另一个是由NSS依赖项dlopen()
.妈的会发生的.
Function calls that need access to NSS or iconv need access will open other libs dynamically, since NSS needs plugins to work (the helper modules like pam_unix.so). When the NSS system dlopens these modules, there will be two conflicting versions of glibc - the one your program brought with it (statically compiled in), and the one dlopen()
ed by NSS dependencies. Shit will happen.
这就是为什么您不能使用getpwnam_r和其他一些功能来构建静态程序的原因.
This is why you can't build static programs using getpwnam_r and a few other functions.
这篇关于为什么不可能完全静态地链接应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!