The question is quite clear I think. I'm trying to write a compiler detection header to be able to include in the application information on which compiler was used and which version.
This is part of the code I'm using:
/* GNU C Compiler Detection */
#elif defined __GNUC__
#ifdef __MINGW32__
#define COMPILER "MinGW GCC %d.%d.%d"
#else
#define COMPILER "GCC %d.%d.%d"
#endif
#define COMP_VERSION __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__
#endif
Which could be used like this:
printf(" Compiled using " COMPILER "\n", COMP_VERSION);
Is there any way to detect LLVM and its version? And CLANG?
Take a look at the Pre-defined Compiler Macros page, select Compilers->Clang. There is information on many other macros for standards, compilers, libraries, OS, architectures and more.
The
__llvm__
and__clang__
macros are the official way to check for an LLVM compiler (llvm-gcc or clang) or clang, respectively.__has_feature
and__has_builtin
are the recommended way of checking for optional compiler features when using clang, they are documented here.Note that you can find a list of the builtin compiler macros for gcc, llvm-gcc, and clang using:
This preprocesses an empty string and spits out all macros defined by the compiler.
For clang, you shouldn't test its version number, you should check for features you want with feature checking macros.
I agree that the best choice is to use has feature macroses, not version macroses. Example with boost:
But anyway, if you need compiler version, you can use boost.predef:
Output examples:
I cannot find an answer here, only links to answers, so for completeness, here is the answer:
I get currently:
Snippet from InitPreprocessor.cpp:
I didn't find any way to get the version of llvm and clang itself, though..