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

后端 未结 2 732
忘掉有多难
忘掉有多难 2021-02-01 08:09

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 application         


        
相关标签:
2条回答
  • 2021-02-01 08:16

    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.

    0 讨论(0)
  • 2021-02-01 08:30

    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.

    0 讨论(0)
提交回复
热议问题