0

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)?

vdenotaris
  • 13,297
  • 26
  • 81
  • 132

2 Answers2

1

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

gcc -DIS_CROSSCOMPILING=1

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 http://www.gnu.org/software/automake/manual/html_node/Cross_002dCompilation.html 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.

Community
  • 1
  • 1
j123b567
  • 3,110
  • 1
  • 23
  • 32
  • `gcc -march=native -E - < /dev/null` makes no sense and is absolutely not guaranteed to fail. Autoconf is trying to run a test binary of the target platform, if it is possible to run it, then "checking whether we are cross compiling..." will output **no**, so if Automake is able to run a.exe via wine, then it will output **no** for MinGW, even on Linux. – Thomas Jul 15 '15 at 07:51
0

Yes it is. #if defined(GNUC) is probably what you are looking for to get the compiler. If you want to see whether a particular target is used, then there might be another macro for the hardware. https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html