Statically linking system libraries, libc, pthreads, to aid in debugging

后端 未结 1 837
野趣味
野趣味 2021-01-28 09:12

I am trying to avoid the situation described in this Stackoverflow entry: Debugging core files generated on a Customer's box. If I compile all the libraries statically wil

相关标签:
1条回答
  • 2021-01-28 09:33

    If I compile all the libraries statically will I avoid having to always gather the shared libraries when it core dumps

    Yes.

    However, contrary to popular belief, statically linked binaries are less portable than dynamically linked ones (at least on Linux).

    In particular, if you use any of these functions: gethostbyname, gethostbyaddr, getpwent, getpwnam, getpwuid (and a whole lot more), you will get a warning at link time, similar to this:

    Using 'getpwuid' in statically linked applications requires at runtime
    the shared libraries from the glibc version used for linking.
    

    What this warning means is that IF your customer has a different version of glibc installed from the one you used at link time (i.e. different from your system libc), THEN your program will likely crash. Since that is a clearly worse situation than your current one, I don't believe static linking is a good solution for you.

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