How to detect the Cross GCC compiler by using macros


I found this really interesting article: C/C++ tip: How to detect the compiler name and version using compiler predefined macros

Is it possible to detect by using a Macro if the current compiler is Cross GCC (the one used as default with Eclipse CDT)?

It is easy to detect, if you are compiling e.g. for ARM, but it is not possible to detect by macro, if you are compiling for ARM on ARM or cros-compiling on x86.

You need support in build system for this and pass your variable to compiler


Using this GCC dump preprocessor defines check yourself output of cross compiler and system compiler. There are lot of defines but nothing about cross compilation.

According to this autotools are performing some check

checking whether we are cross compiling... yes

and I hope that this result can be made visible for gcc.

You can also run some ugly command to check some sort of cross compilation

gcc -march=native -E - < /dev/null

this command will fail, if it is cross compiler to different architecture, but it will not fail, if it is just for different operating system.