Detect ICC vs GCC at compile time

6.7k Views Asked by At

How to detect at compile time if I'm using gcc or icc?

(I was quite puzzled to find out that icc defines __GNUC__ -- and even __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ ! why?)

5

There are 5 best solutions below

0
On BEST ANSWER

We use

#ifdef __INTEL_COMPILER

to split icc off, assuming gcc as a default.

1
On

I believe you could check for __INTEL_COMPILER according to this.

2
On

The reason ICC defines __GNUC__ etc. is because of code like yours that is inspecting compiler-specific macros and expects to see them...

0
On

Traditionally, compilers have defined a symbol of their own as well as their version as preprocessor symbols so that the code could be adapted (generally to work around bugs or specificities).

CLang has introduced a mechanism I had not seen so far, under the form of the __has_feature query. It does not replace the "work around bugs" practices (which is why CLang still exposes specific symbols) but allows a more natural style for querying the compiler capacities. I don't know if other compilers plan on defining such a facility.

0
On

You can make the processor output the defined macros in the preprocessor output and look for a macro that suits you. You can generated the preprocessor output like this:

icc  -dM -E -o foo.P foo.c

Then look at foo.P (since it is a text file). In my case, I found icc defined an __ICC macro with the version of the compiler. It didn't define any __INTEL_COMPILER though.