I\'d like to retrieve the GCC version used to compile a given executable. I tried readelf but didn\'t get the information. Any thoughts?
This information is not stored in the compiled object (c).
Actually, for C code you're totally out of luck. However, for C++ code you may find some information from symbol versions. Some functions from C++ runtime libraries are version-specific, and are marked as such in object files. Try this:
readelf -Wa file.exe | grep 'GCC[[:alnum:]_.]*' --only-match | sort | uniq | tail -n 1
It won't show you the version of GCC used, however. What it shows is the version of symbols in runtime supplied to the compiler. Usually the runtime is that of a compiler shipment, and its version is not less than the one shown with the above command.