Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Broken #if defined behaviour. Works fine in Arduino IDE (Read 121 times)
TheOzMan
Newbies
*
Offline


Posts: 7
Joined: Jan 5th, 2025
Broken #if defined behaviour. Works fine in Arduino IDE
May 9th, 2025 at 8:14am
Print Post  
Visual studio 2022, vMicro 2025.423.2200

I'm writing some code that will support both ESP8266 and ESP32.

To do that, I'm using #if defined statements to define the different headers and code.
Here is a very simple example.

#if defined(ESP8266)
  #include <ESP8266WiFi.h>
#elif defined(ESP32)
  #include <WiFi.h>
#endif

In ardunio ide, this compiles and works fine. 

Using VS and vMicro compiling will also include WiFi.h when only ESP8266 is fined.
ESP32 is NOT defined, thefore should be skipped, but the compiler is just including this anyway.

Even if I change it to just check for a define:
#if defined(ESP8266)
  #include <ESP8266WiFi.h>
#endif

#lif defined(ESP32)
  #include <WiFi.h>
#endif

It still compiles in WiFi.h.

You can see in the attached picture that ESP8266 IS defined and includes the correct header.
ESP32 is NOT define, but just tries to include WiFi.h anyway.

Like I said, this works as expected using the ardunio IDE.

Thanks.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2704
Joined: Feb 13th, 2019
Re: Broken #if defined behaviour. Works fine in Arduino IDE
Reply #1 - May 9th, 2025 at 8:19am
Print Post  
Thanks for the report.

Please attach the complete build output as a text file with the below options enabled:
  • vMicro > Compiler > Verbose
  • vMicro > Compiler > Show Build Properties
  
Back to top
IP Logged
 
TheOzMan
Newbies
*
Offline


Posts: 7
Joined: Jan 5th, 2025
Re: Broken #if defined behaviour. Works fine in Arduino IDE
Reply #2 - May 9th, 2025 at 8:28am
Print Post  
Attached.

You'll see compile errors as it's included WiFi.h and trying to overwrite previous definitions.

Thanks.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2704
Joined: Feb 13th, 2019
Re: Broken #if defined behaviour. Works fine in Arduino IDE
Reply #3 - May 9th, 2025 at 8:48am
Print Post  
If you enable vMicro > Compiler > Deep Search for Libraries + Accurate Prototype Insertion (Gcc-E), and rebuild the sketch it should detect the correct libraries from your #defines (which is the same as the Arduino IDE's Library Discovery process).

With this enabled you can also tune where and how deep the Deep Search Process runs using the options on the vMicro > Compiler Menu.  If you want to know the optimum settings for your project, run the vMicro > Compiler > Run Build Speed & Library Analysis, which will run a clean build and output at the end the best settings.

Build Speed & Library Analysis Documentation: https://www.visualmicro.com/page/Build-Speed-Library-Analysis.aspx

All results from Deep Search are cached as far as possible to improve build times on subsequent builds.

« Last Edit: May 9th, 2025 at 8:49am by Simon@Visual Micro »  
Back to top
IP Logged
 
TheOzMan
Newbies
*
Offline


Posts: 7
Joined: Jan 5th, 2025
Re: Broken #if defined behaviour. Works fine in Arduino IDE
Reply #4 - May 9th, 2025 at 9:04am
Print Post  
Thanks Simon.

That worked perfectly.
Thanks for the quick response!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint