Will a library be able to include a header from another one?

I have added two libraries to my app that have a header duplicated, I was going to suggest that this header was put in a lib of it’s own. A little over kill maybe but I can see this coming up a lot. It’s two Adafruit sensor libs which use a ‘Sensor’ abstract class to try to make the reading of data more generic. So I can see this coming up more as people add Adafruit repositories to the particle IDE.

Anyone have a better solution in mind?

The libs are ‘Adafruit_TSL2561’ and ‘Adafruit_BME280_Library’


That’s something we keep trying to convince people that bringing own copies of “3rd party” libraries is bad practice since that causes such issues, but since these libraries are contributions of volunteers, Particle hasn’t got much say in what people upload - and not the time to “correct” such issues.
So the best way forward would be to raise an issue on the contributors github repo and hope this will be corrected quickle.
And if not, you may have to remove one of the libraries and re-add it as seperate file tabs without the duplicate header(s).

An alternative might be to try out one of the other TLS2561 libraries on Build (although having multiple libs for one device/sensor is also not desirable)

But after looking at the two libraries you refered to, the Adafruit_Sensor.h has got a protection against double inclusion, so your code should still build even with both libs bringing their own version.

Yes I thought that too, the error is in the ino file and I have noticed over the years this file does not follow the same rules. Not been able to pin it down, just worked around the issues. The two copies of the headers are the same. I think Arduino tool chain is doing something funky with the dependencies and headers when it compiles the ino file.

I’ve switched to CE_BME280 with looks to be the same but with out the dependency of the header. It also seems that for the Adafruit_BME280_Library lib it’s not using the structs in the header anyway so could be deleted. I’ll raise an issue with the author.


1 Like