Arduino magic? Compiler option? #ifdef #include #endif

The following code compiles with Arduino IDE 1.8.4 but fails with PlatformIO because it includes
RF24_STM32.h–although it’s guarded.

#define __AVR_ATmega328__

#ifdef __AVR_ATmega328__
#include <RF24.h>
#elif STM32_MCU_SERIES && STM32_MCU_SERIES == STM32_SERIES_F1
#include <RF24_STM32.h>
#endif /* ifdef __AVR_ATmega32 */


int main() {
  RF24 radio(9,10);
  }

I searched this forum, stackoverflow, cpp reference etc. but could not find a hint.
Is this a compiler setting I can change?
One solution might be to change the compile options, i.e. change the include directory when target is STM32 and renaming one library. But maybe there is a simple inline solution?

Thanks for pointing my in the right direction.
Best

Were the PlatformIO people unhelpful?

#define __AVR_ATmega328__

Well; THAT shouldn't need to be there; it should be getting defined for you by the compiler/etc.
PlatformIO is supposed to be aggressively multi-platform - are you sure you're building what you think you're building?

Thanks for your replies.
That sounds like a I'm mistaken and the observed compiler behavior has nothing to do with Arduino "compiler magic". Moreover, I derive from your questions it is not C++ specific either. Hence, I'll head over to PIO to discuss it there.

westfw:

#define __AVR_ATmega328__

Well; THAT shouldn't need to be there; it should be getting defined for you by the compiler/etc.

I added this for Arduino IDE not for PlatformIO. :wink:

Best

terraduino:
I added this for Arduino IDE not for PlatformIO. :wink:

The point @westfw was trying to make is that the Arduino IDE automatically includes such #defines when building.

If you had used the correct identifier (AVR_ATmega328P) in your condition it would have worked as @westfw described...

#if defined( __AVR_ATmega328P__ ) || defined( __AVR_ATmega328__ )

@CodingBadly
Sorry, but I don’t understand. Is this somehow related to my original question or just a side note?

If related: the #define AVR_ATmega328, IMHO, has nothing to do with my problem.
I could have posted this sketch and the original problem persists:

#define MYGUARD12 

#ifdef MYGUARD12
#include <RF24.h>
#elif MYGUARD14
#include <RF24_STM32.h>
#endif /* ifdef __AVR_ATmega32 */


int main() {
  RF24 radio(9,10);
}

Thanks & best