By Darryl Gove-Oracle on May 19, 2008
If you need to find out which version of the compiler is installed use:
$ cc -V cc: Sun C 5.9 SunOS_sparc 2007/05/03
I've not been able to find a table which maps the version numbers back to the product names. For the record this is Sun Studio 12.
A more interesting question is what compiler generated an executable.
$ mcs -p test.o test.o: acomp: Sun C 5.8 2005/10/13 as: Sun Compiler Common 11 2005/10/13
The test file was generated by Sun Studio 11.
Finally what flags were used to generate an executable. Use dwarfdump and grep for "command" for binaries generated with Sun Studio 12, or for C code compiled with Sun Studio 11.
$ dwarfdump test.o|grep command DW_AT_SUN_command_line /opt/SUNWspro/prod/bin/cc -xtarget=generic64 -c test.c < 13> DW_AT_SUN_command_line DW_FORM_string
For older compilers use dumpstabs and grep for "CMD":
$ getr.o|grep CMD 2: .stabs "/export/home; /opt/SUNWspro/bin/../prod/bin/cc -c -O getr.c",N_CMDLINE,0x0,0x0,0x0
Of course it's very unlikely that shipped binaries will contain information about compiler flags.