简体   繁体   中英

How do I find what libraries need to be installed on a client linux machine if I compile a binary with a newer version of gcc?

Say I have a C++ binary that was compiled with a version of gcc say 4.4.x, which is used on a client linux box.

If I want to upgrade my compiler to use a newer one, say 4.9.3 (because I want to use C++11):

What kind of things would need to be upgraded on the client box to run this new binary? (eg .so libraries) And how would one find this out?

I'm guessing from the fact that you mention GCC 3.4 that your client system is running RedHat/CentOS/Scientific Linux 4 which is so old that even Red Hat ended support for it three years ago . If you were running any newer version then you would have been able to take advantage of the Developer Toolsets which include a modified version of GCC that statically links newer parts of the standard library into your binary so that it can run on legacy systems without newer glibc/libstdc++ runtimes.

There are two mechanisms to test compatibility of shared libraries:

  1. The SONAME : a canonical name for the library that is used by the linker to reference the library. You can query the list of required libraries for every ELF object (executable or library) with the ldd command, and you need to do this recursively for each referenced library to get a full list of libraries needed.

  2. The symbol version information. This is an additional constraint that allows adding functionality to existing libraries by introducing version requirements per symbol used -- a program only using symbols that have existed for ages will require a lower minimum version of the library than one that uses new functionality.

Both of these need to be fulfilled in order for the program to run.

The typical approach of Linux distributions is to keep a mapping of SONAME to package name (as multiple versions differing in SONAME can be installed concurrently), and a table of versioned symbols to the package revision these were introduced. The appropriate package development tools for your distribution should be able to create a list of dependency specifications that matches your program's requirements; if they fail to do so because symbols are unknown, it is likely that this version cannot be supported on that release of the distribution.

What kind of things would need to be upgraded on the client box to run this new binary?

You will need to ship two shared libraries with your application: libgcc_s and libstdc++ . See https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html for more details.

You can ship these libraries in the same directory with your executables if you link using $ORIGIN . See https://stackoverflow.com/a/4742034/412080 for more details.

And how would one find this out?

Run ldd and readelf -d on your executables to see what libraries they need.

An alternative could be to link statically all libraries (notably libstdc++ ) other than the libc (and libm and libdl if you use them); then the produced ELF executable depends only of the libc ; however, with ancient enough kernels or libc (on the target machine) even that might fail to work...

For details, read Drepper's paper: How To Write Shared Libraries

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM