简体   繁体   中英

How to detect Cross GCC compiler 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 eg 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM