tags:

views:

95

answers:

2

Is there a way to print the name of the compiler and the version that was used to compile a program, something like;

printf("This is compiled with %s version %s\n", COMPILER, COMPILER_VERSION);

?

+4  A: 

No, the way to get the name of the compiler is itself compiler-specific :-P.

gcc provides the __VERSION__ macro, though.

Borealid
+9  A: 

You can do this with the pre-processor:

Reference: http://predef.sourceforge.net/precomp.html

For gcc:

#if defined(__GNUC__)
# if defined(__GNUC_PATCHLEVEL__)
#  define __GNUC_VERSION__ (__GNUC__ * 10000 \
                            + __GNUC_MINOR__ * 100 \
                            + __GNUC_PATCHLEVEL__)
# else
#  define __GNUC_VERSION__ (__GNUC__ * 10000 \
                            + __GNUC_MINOR__ * 100)
# endif
#endif

For MSVC just use:

_MSC_FULL_VER
Vitor Py
+1: you beat me too it ;)
D.Shawley
Err... What if I used microsoft's compilers?
Arafangion
_MSC_FULL_VERTake a look at the link. It's a reference for compiler specific pre processor defines.
Vitor Py