I am building my own library which is supposed to work both on an arm mbed and on linux platforms. If the target is ARM mbed, then the library needs to be cross-compiled with arm-none-eabi-gcc
while if the target platform is linux, the library needs to be compiled with gcc
. Is there a predefined compiler macro that will allow me to determine which compiler was invoked to compile the library? Note that Raspberry Pi which
has an ARM CPU also needs to be supported so I cannot use any arch macros.
Asked
Active
Viewed 2,162 times
0

niko
- 1,128
- 1
- 11
- 25
-
Possible duplicate of [GCC dump preprocessor defines](http://stackoverflow.com/questions/2224334/gcc-dump-preprocessor-defines) – Eugene Sh. Apr 07 '17 at 21:09
-
I already tried the suggestions in this thread, but there are a lot of macros and it takes ages to go through all of them one by one. – niko Apr 07 '17 at 21:29
-
Try comparing the lists generated by the two compiler using some `diff`. Or look here: https://gcc.gnu.org/onlinedocs/cpp/System-specific-Predefined-Macros.html#System-specific-Predefined-Macros – Eugene Sh. Apr 07 '17 at 21:30
-
already tried `diff` too: the output is twice as long... The link however helped me find a possible answer. Seems like `__unix__` can work. Thanks! – niko Apr 07 '17 at 21:39
-
You're doing it bass-ackwards, I think. You should either have a simple `configure` script (run before `make`) to select the target architecture; or have a Makefile with the different targets (so `make mbed` compiles ARM mbed version, `make linux` a generic Linux version, `make pi` for Raspberry Pi, and so on); with those defining some preprocessor macros your code can use if there are code-level differences. – Nominal Animal Apr 07 '17 at 21:45
-
If the output with diff is twice as long, you are doing it wrong... – Marc Glisse Apr 07 '17 at 23:17
2 Answers
0
As suggested by the comments and this link: https://gcc.gnu.org/onlinedocs/cpp/System-specific-Predefined-Macros.html#System-specific-Predefined-Macros, the macro __unix__
will be defined by gcc
but not by arm-none-eabi-gcc
. If anyone has a better answer, please post it.

niko
- 1,128
- 1
- 11
- 25
0
According to ARM Compiler Toolchain Reference, macro __arm__
is always defined for the ARM compiler arm-none-eabi-gcc
.

Serge Goncharov
- 488
- 1
- 6
- 13