Go Down

Topic: How to specify a path to a specific header file? (Read 1 time) previous topic - next topic

lupacexi

Aug 24, 2017, 02:50 pm Last Edit: Nov 10, 2017, 06:19 pm by lupacexi
I'm looking for a way to tell the #include statement where to look for a specific header file.

For example, if I have library ABC that includes a file called xyz.h, but I also have library HAL with a file called xyz.h. How do I tell the compiler which one to use? I tried unsuccessfully to add a path as part of the name, and I also tried copying the desired libraries to the sketch folder - it worked a little better but still found the other header and tried to use it instead.

Here is an example that doesn't cause too much problems as the header files appear to be identical: Both the Ethernet and Ethernet2 libraries have header files with identical names (such as Dhcp.h) in their folders, and when compiling it points out bitterly that it had to pick one over the other. Sometimes it grabs them from the Ethernet folder, sometimes from the Ethernet2 folder.

So is this something that can be done?

PaulS

Quote
For example, if I have library ABC that includes a file called xyz.h, but I also have library HAL with a file called xyz.h.
A) You should NOT be doing that.
B) You can use complete paths in an include statement. But, see A.

Robin2

The Arduino system has some severe limitations in its ability to work sensibly with the file system - can be a real PITA.

As @PaulS has said you could give a complete path name - but that can be a PITA if you need to move things around.

Another option is to rename one of the libraries so that you can refer to it by a distinct name.

I use the Geany editor and I have a Python uploader program that converts relative path names to full path names before calling the IDE comand line to compile or upload my code

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

RayLivingston

If you have two include files with the same filename, the IDE may, or may not, find the one you want.  It searches in its own order, and will take whichever one it finds first, and you can't easily force it to take the one you want.  And giving full paths in the #include statement will eventually create a whole different set of problems.  The only sensible solution is: Don't have two include files with the same name.

Regards,
Ray L.

Go Up