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 Header file inclusion odd behaviour (Read 2057 times)
Acuario
Full Member
***
Offline


Posts: 233
Location: Spain
Joined: Aug 28th, 2015
Header file inclusion odd behaviour
Sep 17th, 2021 at 6:30am
Print Post  
I have been trying to get to grips with reducing the compile time of my project (several minutes!).
I had deep search for libraries enabled so disabled this only to get loads of no such file or directory errors. With deep search enabled my project compiles without errors - just verrrrrry slowly...

I slowly went through and added these using Micro Explorer (Explore platforms/Esp8266/Libraries/All) and clicking on each supposedly missing library - the 'strange' thing is that each added library adds the library to the solution - is this correct?

Also, the headers were added to the project .ino file.
I like to separate headers from code as for me it is neater and easier to work on so I have a header file that includes all the headers that is then #included in the .ino and in other .h files where needed.

After adding the libraries as above all compiled ok.

As it seemed strange to have the libraries included in the solution I tried deleting one.
To my surprise my project then failed to compile although the library header was in my header file.

Experimenting I have discovered the following:

If a library header is included in the .ino file then the project will compile.
If the library header is included in a header file that is included in the .ino file the library is not found.

See the following that compiles correctly:

Code (C++)
Select All
File: Sketch1.ino

#include <Wire.h>
void setup() {
	Wire.begin(4, 5);
}
void loop() {
 
}
 



..and the following that does not:

Code (C++)
Select All
File: Sketch1.h
#include <Wire.h>

File: Sketch1.ino

#include "Sketch1.h"
void setup() {
	Wire.begin(4, 5);
}
void loop() {
 
}
 



Is this an 'Arduino' "Feature" or should this work correctly?

Is this a case for having just an empty .ino file (so VM et al recognises it as an Arduino project) and the code in a .cpp file with its associated header?
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2174
Joined: Feb 13th, 2019
Re: Header file inclusion odd behaviour
Reply #1 - Sep 17th, 2021 at 11:56am
Print Post  
Thanks for the report.

The libraries are added as Shared Projects to the Solution, when the vMicro > Add Library > "Clone for Solution When Including Libraries" option is Enabled.

If you delete one of the Shared Project from the solution, you will also need to remove the reference in your main INO project.

When the sketch fails to compile, have you added the Sketch1.h to the INO Project in solution explorer?

Please attach the build output when the compilation fails, with the verbose and Show Build Properties options Enabled (shown at the top of this page), along with a picture of the solution explorer with References, Header Files, and Source Files expanded.
« Last Edit: Sep 17th, 2021 at 11:59am by Simon@Visual Micro »  
Back to top
 
IP Logged
 
Acuario
Full Member
***
Offline


Posts: 233
Location: Spain
Joined: Aug 28th, 2015
Re: Header file inclusion odd behaviour
Reply #2 - Sep 17th, 2021 at 4:10pm
Print Post  
I don't have "Clone for Solution When Including Libraries" enabled but I do have "Create shared project when including libraries" enabled.

Disabling this stops the library being added to the solution so one down...

I added the .h file using the Add/New item/Header file from the solution explorer - the header file is listed under Header Files in the solution explorer.

Files attached as requested.

  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Acuario
Full Member
***
Offline


Posts: 233
Location: Spain
Joined: Aug 28th, 2015
Re: Header file inclusion odd behaviour
Reply #3 - Oct 17th, 2021 at 5:30am
Print Post  
Hi,
did you manage to take a look at this? It still is a problem in the latest VM version.
I checked it out using the Arduino IDE (yuck..) and it compiles correctly with the header including the other header(s).

If deep search is on then the sketch compiles, with deep search off it fails:

Quote:

Sketch5.h: 2:10: fatal error: Wire.h: No such file or directory
   2 | #include <Wire.h>
   |          ^~~~~~~~
   compilation terminated
Build failed for project 'Sketch5'
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Header file inclusion odd behaviour
Reply #4 - Oct 17th, 2021 at 4:10pm
Print Post  
It should build fine. The Arduino IDE always has deep search on, you can not switch it off.

If you do not add an #include for each of all required libraries into the .ino code, then you need deep search ON.

Arduino and Visual Micro work the same way. The deep search can be slow therefore we give ability to switch it off but hopefully with clear understanding about the requirement for #include(s) in .ino code.

Libraries that are #included in code outside of .ino code, either directly in cpp or indirectly via the code of another library will only be discovered and compiled if deep search is ON (or if shared libraries are used)

Shared Library Note

Currently, shared libraries can be cumbersome to work with when switching architecture or toolchain versions. This is because the location of the library becomes static. Static is useful if we want to ensure specific library versions are used for a project, but can be confusing for some users. The dynamic "arduino documented" library discovery that only requires #includes, makes use of deep search. That is why deep search is recommended for an easier "arduino" life.
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint