#error is ignored on compile (Solved)

Hi,

I am running platformio under vscodium, developing with the Arduino libraries.
This is a segment of code from a project I'm currently developing that should error out if none of the flags are defined.
The error is printed to the console, but compilation does not halt. It carries on, spamming the console with errors related to the code that it shouldn't even try to compile.

#if !defined(USE_DS1307) && !defined(USE_DS3231) && !defined(ESP32)
#error "ERROR: This configuration is not supported on platforms other than ESP32."
#endif

This is intended to be a cross-platform project with certain aspects of the code only compiled for specific platforms.
The compiler should only continue compiling if any of these three macros is defined, and error out if they aren't. Instead, it blindly carries on.
Is there any possible reason for this? Is it possibly some stupid setting that platformio defaults to, treating an error as a warning?

Would appreciate any help. Thanks in advance.

You probably want or || not &&

Nope. I want it to fail if ALL of those macros are undefined.
The compiler hits the #error and displays it, but continues blindly compiling.
Thanks. MH

OK. Just as a test try this to see which fail

#if !defined(USE_DS1307)
#warning "not defined USE_DS1307"
#endif

#if !defined(USE_DS3231)
#warning "not defined USE_DS3231"
#endif

#if !defined(ESP32)
#warning "not defined ESP32"
#endif

but I don't know how you configure this to respect preprocessor errors:

Thanks for the info.
EDIT: They all trigger warnings when I recompile.
Forgot to mention. This is all inside a header file with include guards.

maybe #ifndef instead of #if !defined(ESP32)
#warning may not be supported by all compilers

Same result with #ifdef I'm afraid.

i get the following when i added it to some code


Tst:18:4: error: #error "ERROR: This configuration is not supported on platforms other than ESP32."
 #  error "ERROR: This configuration is not supported on platforms other than ESP32."
    ^~~~~
exit status 1
#error "ERROR: This configuration is not supported on platforms other than ESP32."

Do you think it might be my build environment then?
Perhaps it's some stupid default. Does anyone know how to override it or check the settings?
This is vscodium/vscode with the platformio plugin.
The platform.ini has no extra compiler switches added from the defaults.

all i did was run the compilation not the upload button

when i use upload, it always upload, or at least run the code on the target regardless if there is an error. presumably this is not suppose to happen and i just assumed it was some setting in my environment

The same #error here, when compiled for a non-ESP32 board.
Compiling for an ESP32 board succeeds.

It seems to work now! Not sure what on earth was going on.
Thanks for the help though!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.