On Tue, 14 Feb 2006, Gelu Ionescu wrote: > How can I detect the compiler version used to generate a .a or .so library?
Hi Gelu, As far as I know, the GNU compilers don't interlace a compiler stamp or similar into the output code. Precisely speaking, a library is generated by a linker, not a compiler; you can in principle build a library from object files which have in turn been compiled with different compiler versions. If you compile the sources yourself, you may include something like static char _gcc_vers[] = __VERSION__; in your sourcefiles (or otherwise hope the author did), which you can extract by "strings mylib.so" for example (along with many unwanted "junk", so have a good eye or filter). However, since gcc/g++ v3.X (and the corresponding linker!), the ABI permits per some insight into the genesis of compiled code by default, as long as symbols are not stripped from the binaries. Try: nm -C mylib.so | grep @@GLIB | sed 's/^.*@@//' | sort -u The output (if above conditions are fulfilled) will look like this: GLIBC_2.0 GLIBC_2.1 GLIBC_2.1.3 GLIBC_2.2 GLIBC_2.3 GLIBCPP_3.2 GLIBCPP_3.2.2 (Change the grep argument, if only g++ output wanted, but be aware that the acronym changed later for GLIBCXX, as "CPP" was already in use as a tag for the preprocessor.) The output means the following: The most recent (in terms of compiler used) function calls in mylib.so go to a function/binary/library, which has been compiled with gcc v2.3 or g++ v3.2.2 respectively. This gives you a _lower_ limit on the version of the compiler which was used to generate the code which calls the function. In most cases, this should however be what you want to know. ("Is my library compatible or more recent than the compiler I want to use to put my program together?") Details on the ABI are available at: http://gcc.gnu.org/onlinedocs/libstdc++/abi.html PS: This reasoning can be bowled down, if you can not assume "linear" compiler installation/evolution on your platform, i.e. that some one linked a newer library with an older compiler, which may entail a lot of other problems then anyway. _______________________________________________ Help-gplusplus mailing list Help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus