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 What determines header files to be included when adding library? (Read 1544 times)
Acuario
Full Member
***
Offline


Posts: 233
Location: Spain
Joined: Aug 28th, 2015
What determines header files to be included when adding library?
Jan 2nd, 2022 at 8:18am
Print Post  
When adding a library to a sketch, sometimes a bunch of header files are added - in some cases the headers do not seem to exist.

For example, adding the modbus-esp8266 library to a project adds the following headers:

#include <write.h>
#include <read.h>
#include <files.h>
#include <common.h>
#include <ModbusTLS.h>
#include <ModbusTCPTemplate.h>
#include <ModbusTCP.h>
#include <ModbusSettings.h>
#include <ModbusRTU.h>
#include <ModbusIP_ESP8266.h>
#include <ModbusEthernet.h>
#include <ModbusEthernet-v1.h>
#include <ModbusAPI.h>
#include <Modbus.h>
#include <darray.h>

..when really all that needs to be added is:
#include <ModbusIP_ESP8266.h>

Running a compile with the full list then throws an error that <write.h> does not exist (I don't have deep search enabled).'

Removing all but the needed include builds correctly.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: What determines header files to be included when adding library?
Reply #1 - Jan 3rd, 2022 at 12:30am
Print Post  
The Arduino specification caters for a list of header files to be configured in the "library.properties" text file. The text file is supplied with Arduino v2 format libraries (most are v2, the older v1 is used less these days). 

If the property is not provided in the library.properties text file then all headers found in the library root (or \src for vs2 libs) are used. 

The Arduino IDE should use the same logic. 

You are right you often only need one or two headers depending on which part of the library code you are using. Ideally a library author would put "private" headers in a subfolder of the [library]\src folder. That would simply the library usage for users.
  
Back to top
WWW  
IP Logged
 
Acuario
Full Member
***
Offline


Posts: 233
Location: Spain
Joined: Aug 28th, 2015
Re: What determines header files to be included when adding library?
Reply #2 - Jan 3rd, 2022 at 5:04pm
Print Post  
Thanks for the explanation. I see some (very few!) libraries.properties do have an includes= section so this makes sense.

From what you explain though it doesn't make sense that (in this particular case) there are several headers added that aren't in the src folder (I haven't tried other libraries to see if this is a common occurrence).

Specifically with this library the following headers are added that are not in the src folder, and apart from common.h don't seem to exist.

#include <write.h>
#include <read.h>
#include <files.h>
#include <common.h>

I've looked at all the files in the src folder and none of them include any of the above so why are they added?
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: What determines header files to be included when adding library?
Reply #3 - Jan 4th, 2022 at 12:40am
Print Post  
Please provide the information request in the yellow box above. That will show from where files are discovered. It is always useful to have this info.
  
Back to top
WWW  
IP Logged
 
Acuario
Full Member
***
Offline


Posts: 233
Location: Spain
Joined: Aug 28th, 2015
Re: What determines header files to be included when adding library?
Reply #4 - Jan 4th, 2022 at 4:52am
Print Post  
The library is form https://github.com/emelianov/modbus-esp8266

The sketch is the example client.ino

The successful build is the unmodified sketch.
The fail is when the library is added from 'Add Library' (adds the headers in post #1)

I've emailed the build as the forum has no option to attach files  Huh
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint