0

I've got the problem that my program will compile with g++10.2 and c++11 activated through cmake. but it will not compile with arduino dues arm-none-eabi-g++.exe compiler which also has c++11. The failure occurs because of one line that needs to be added for the arm compiler, but when I add that line to g++10.2 it won't compile.

So I need an #ifdef or some alternative to activate and deactivate the line specific for the compiler.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
Gian Laager
  • 474
  • 4
  • 14
  • See https://stackoverflow.com/questions/2224334/gcc-dump-preprocessor-defines to find predefined macros for both of your compilers. You can then use one that is defined differently between the two compilers. – Mankarse Jul 20 '21 at 06:14
  • try to use ```__arm__```, ```__aarch64__``` or ```__ARM_ARCH``` macro – Deumaudit Jul 20 '21 at 06:21

1 Answers1

0

Like Deumaudit said in the comments:

Try to use __arm__, __aarch64__ or __ARM_ARCH macro

You'll probably be ok if you use #ifdef __arm__ or even #if defined(__arm__) || defined(__aarch64__)

If you're planning to add more supported platforms to your program, it might be a good idea to define some macros when building for a specific platform. I have my own _MY_APP_ARM macro defined in my CMakeLists.txt:

if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
    add_definitions(-D_MY_APP_ARM)
endif()

Which I can then use as #ifdef _MY_APP_ARM

T. J. Evers
  • 391
  • 1
  • 13