Why would it be impossible to fully statically link an application?

感情迁移 提交于 2019-12-03 05:07:01

问题


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

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?


回答1:


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.

This is why you can't build static programs using getpwnam_r and a few other functions.




回答2:


AFAIK, it's not impossible to fully statically link an application.

The problem would be incompatibility with newer library versions which might be completely different. Say for example printf(). You can statically link it, but what if in a future that printf() implementation changes radically and this new implementation is not backward-compatible? Your appliction would be broken.

Please someone correct me if I'm wrong here.



来源:https://stackoverflow.com/questions/8140439/why-would-it-be-impossible-to-fully-statically-link-an-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!