Sketch doesn't find header file

I’ve read around the Forum and I thought I had this sorted out.

I am coding for a project using nRF24L01 communication called GHTS, and I want to store routines common to both master and slaves in an Header file. The folder setup is shown in the attached .PNG.

File → Preferences → Sketchbook Location → …\Programming\Arduino\GHTS

The GHTS_Private.h sub-folder has GHTS_Private.h.ino
The GHTS_Private sub-folder has GHTS_Private.ino
The GHTS sub-folder has GHTS.ino

There is nothing in the "libraries’ folder.

GHTS.ino is

#include "GHTS_Private.h"
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>


void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Building GHTS.ino results in

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware "C:\Program Files (x86)\Arduino\hardware" -hardware "C:\Users\Rick\AppData\Local\Arduino15\packages" -tools "C:\Program Files (x86)\Arduino\tools-builder" -tools "C:\Program Files (x86)\Arduino\hardware\tools\avr" -tools "C:\Users\Rick\AppData\Local\Arduino15\packages" -built-in-libraries "C:\Program Files (x86)\Arduino\libraries" -libraries "D:\Ad. Dip. Mech. Eng\_Semester 2 2016\Select - Remy\Programming\Arduino\GHTS\libraries" -fqbn=arduino:avr:uno -ide-version=10609 -build-path "C:\Users\Rick\AppData\Local\Temp\buildc782674162b28c30110d985a07bf946b.tmp" -warnings=none -prefs=build.warn_data_percentage=75 -verbose "D:\Ad. Dip. Mech. Eng\_Semester 2 2016\Select - Remy\Programming\Arduino\GHTS\GHTS\GHTS.ino"
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware "C:\Program Files (x86)\Arduino\hardware" -hardware "C:\Users\Rick\AppData\Local\Arduino15\packages" -tools "C:\Program Files (x86)\Arduino\tools-builder" -tools "C:\Program Files (x86)\Arduino\hardware\tools\avr" -tools "C:\Users\Rick\AppData\Local\Arduino15\packages" -built-in-libraries "C:\Program Files (x86)\Arduino\libraries" -libraries "D:\Ad. Dip. Mech. Eng\_Semester 2 2016\Select - Remy\Programming\Arduino\GHTS\libraries" -fqbn=arduino:avr:uno -ide-version=10609 -build-path "C:\Users\Rick\AppData\Local\Temp\buildc782674162b28c30110d985a07bf946b.tmp" -warnings=none -prefs=build.warn_data_percentage=75 -verbose "D:\Ad. Dip. Mech. Eng\_Semester 2 2016\Select - Remy\Programming\Arduino\GHTS\GHTS\GHTS.ino"
"C:\Users\Rick\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.3-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10609 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Users\Rick\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.13\cores\arduino" "-IC:\Users\Rick\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.13\variants\standard" "C:\Users\Rick\AppData\Local\Temp\buildc782674162b28c30110d985a07bf946b.tmp\sketch\GHTS.ino.cpp" -o "nul"
"C:\Users\Rick\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.3-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10609 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Users\Rick\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.13\cores\arduino" "-IC:\Users\Rick\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.13\variants\standard" "C:\Users\Rick\AppData\Local\Temp\buildc782674162b28c30110d985a07bf946b.tmp\sketch\GHTS.ino.cpp" -o "C:\Users\Rick\AppData\Local\Temp\buildc782674162b28c30110d985a07bf946b.tmp\preproc\ctags_target_for_gcc_minus_e.cpp"
D:\Ad. Dip. Mech. Eng\_Semester 2 2016\Select - Remy\Programming\Arduino\GHTS\GHTS\GHTS.ino:29:26: fatal error: GHTS_Private.h: No such file or directory

 #include "GHTS_Private.h"

                          ^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

So much for having it sorted out :disappointed_relieved: .

What do I still have twisted?

Thanks

GHTS Folder Setup.PNG

This

#include "GHTS_Private.h"

will lead the compiler to expect to find that file in the same folder as the file GHTS.ino

IMHO it is a big weakness of the simplifcations made by the Arduino system that the normal way to share a file between two programs is by putting it in a library.

This is because the IDE first copies all the files to another folder before it tries to compile any of them and relative links from that other folder obviously fail.

You can work around that by giving a full path name in your #include

I have written a Python program that expands relative path names properly before bundling everything into a folder that the IDE can deal with.

...R

All of your sketch files should be in one sketch folder or in libraries.

SketchFolder
    GHTS
        GHTS.ino
        GHTS_Private.h   (NOT .h.ino)
        GHTS_Private.ino  (or .cpp)

If you have some source files you don't want in the base folder you can put them in a sub-folder. I think it may have to have a special name like 'src' or 'util':

SketchFolder
    GHTS
        GHTS.ino
        src 
            GHTS_Private.h   (NOT .h.ino)
            GHTS_Private.ino  (or .cpp)

If the '_Private' stuff will be used by multiple sketches you would typically put it in a library folder:

SketchFolder
    GHTS
        GHTS.ino
    libraries
        GHTS_Private
            GHTS_Private.h   (NOT .h.ino)
            GHTS_Private.cpp  (I don't know if .ino would work in a library)

I tried a relative pathname

#include ".\..\GHTS_Private.h\GHTS_Private.h"

but I still get

D:\Ad. Dip. Mech. Eng\_Semester 2 2016\Select - Remy\Programming\Arduino\GHTS\GHTS\GHTS.ino:29:46: fatal error: .\..\GHTS_Private.h\GHTS_Private.h: No such file or directory

 #include ".\..\GHTS_Private.h\GHTS_Private.h"

                                              ^

compilation terminated.

I suspect that this is because what should be a .h file is, in fact GHTS_Private.h.ino - the name the IDE gave it. So I copied the file and renamed it GHTS_Private.h and I still get

D:\Ad. Dip. Mech. Eng\_Semester 2 2016\Select - Remy\Programming\Arduino\GHTS\GHTS\GHTS.ino:29:46: fatal error: .\..\GHTS_Private.h\GHTS_Private.h: No such file or directory

 #include ".\..\GHTS_Private.h\GHTS_Private.h"

                                              ^

compilation terminated.

Three things:

  1. Has my 20-year-old DOS :astonished: failed me and the relative address is incorrect?
  2. Considering the IDE named the header file .h.ino why does the compiler not recognize it? :-\
  3. How dare the compiler tell me that neither of these files exists? :angry:

Taking a hint from johnwasser I shifted the .h and .ino header files into the same folder as GHTS.ino. When I woke up to what the compiler error messages meant I removed the void setup() and void loop() code from each of those files and all compiled well. It appears to link - well, at least the compiler has found the files.

Here comes the hard bit: :fearful:

I actually want two sketches, one to run a stationary console and the other to run a mobile vehicle. Communication between the two is to be using the nRF24L01 PCB. I created the sketches in the GHTS folder and named them GHTS_Console.ino and GHTS_Trolley.ino. Now the Arduino IDE insists that each be in its own folder, and that necessitates two copies of the .h and .ino header files. From my programming experience, that is a recipe for disaster. Configuration Management becomes a nightmare if you start doing things like that.

Now, robin2 suggested a work-around for that by addressing these files in the #include statement. If I can get that to work then I can have just the one copy of each with both of them accessible to my two sketches.. Once again, however,

#include ".\..\GHTS_Private.h\GHTS_Private.h"

gets spat out by the compiler.

What is the key to addressing the files in the #include statement?

vagulus:
Now, robin2 suggested a work-around for that by addressing these files in the #include statement.

I suggested that you use a full path name - NOT a relative path.

I also mentioned that relative links fail :slight_smile:

...R

Sorry about my missing the significance of the word relative. I guess my computerese is a little rusty. :sob:

I am certainly having difficulties with the IDE creating new folders all over the place. It’s driving me even nuttier. :fearful: I moved the .h file to near-root so as to minimize the real path. Now the compiler persists in looking where the file was (see attachment)! This even after rebooting the PC! :angry:

How do I get the compiler to look where I tell it - now that I am really telling it? :wink:

Windows really does NOT like spaces in directory names. Try putting the files in D:\GHTS_Private.

vagulus:
I actually want two sketches, one to run a stationary console and the other to run a mobile vehicle. Communication between the two is to be using the nRF24L01 PCB. I created the sketches in the GHTS folder and named them GHTS_Console.ino and GHTS_Trolley.ino. Now the Arduino IDE insists that each be in its own folder, and that necessitates two copies of the .h and .ino header files. From my programming experience, that is a recipe for disaster.

The proper mechanism for that is a library. As I said before: if the '_Private' stuff will be used by multiple sketches you would typically put it in a library folder:

SketchFolder
    GHTS_Console
        GHTS_Console.ino   (use #include "GHTS_Private.h" to reference the library)
    GHTS_Trolley
        GHTS_Trolley.ino
    libraries
        GHTS_Private
            GHTS_Private.h   (NOT .h.ino)
            GHTS_Private.cpp  (I don't know if .ino would work in a library)

vagulus:
I am certainly having difficulties with the IDE creating new folders all over the place.

I agree.

I don't use the IDE, I use Geany to edit my programs and my Python program can be called from Geany. It takes care of shaping everything into the style the IDE requires and then calls the IDE to compile or upload the program.

...R

Hi again johnwasser

GHTS_Console.ino has

#include "GHTS_Private.h"
#include <RF24.h>
#include SPI;


void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

I have renamed the folders to eliminate spaces in folder names.
My file structure is shown in the attachment.

Compiling results in

D:\AdDipMechEng\_Semester_2_2016\Select_Remy\Programming\Arduino\GHTS\GHTS_Console\GHTS_Console.ino:35:26: fatal error: GHTS_Private.h: No such file or directory

 #include "GHTS_Private.h"

                          ^

compilation terminated.

Changing GHTS_Private.ino to GHTS_Private.cpp doesn’t change anything, although you will note that the compiler is still looking for GHTS_Private.ino.

Hi again robin2

In my current state of confusion, I suspect that the addition of another IDE and an add-in program to the mix would be the coup de grace. :roll_eyes: However, the issue of the Arduino having a counter-productive mind of its own is too important to ignore. While it is important, it is a separate issue from the issue for which this thread was created so I am going to open another thread in Installation and Troubleshooting to discuss some IDE bad habits.

See you there.

In my brief association with the world of Arduino I have been impressed by the quality of the website and its content, and by the speed and quality of the advice people produce in response to my plaintive pleas. I wish I could say the same of the IDE. :sob:

My programming experience includes COBOL, Pascal, Ada, C, C++, and Assembler (none of which gave me any useful experience in programming mechanical devices). I have never seen an IDE which insists on each program being in its own folder, and the massive problems that creates when trying to link several sketches to the one header file. This feature restricts the IDE user to simple, monolithic programs, and denies the programmer the freedom to employ standard Software Engineering practices (such as the use of header files). It seems to me to be much better, and much simpler, to allow the creation of one 'Project' folder to hold all the project files, and to allow the sketches and headers to work together in that.

How do you Forum members feel about this issue?

Sketches may consist of multiple files, these are shown in the IDE as tabs. If you threw all your sketches in one folder how would the IDE know which files belonged to which project? To get around that you'll need a metadata file. Pretty soon that folder is going to be a huge mess. You'll have issues with duplicate filenames. I find it very convenient to have a separate folder for each project. I can store notes and documentation and other associated files in that folder. I use git for version control on all but the simple sketches and that will require it to be in its own folder also.

The thing I think is dumb is that the IDE forces you to have the folder name the same as the sketch. Sure that's probably a good idea anyway but no need to make it a requirement.

vagulus:
the massive problems that creates when trying to link several sketches to the one header file.

You're going to have to explain these massive problems. I'm not aware of any. Maybe you don't understand how the Arduino IDE library system works?

My own POV is that the current IDE style is just fine for people like myself coming back into electronics.
And even better for some of the very young people coming into Arduinos.

Its pretty simple and sort of STD so its easy to give out help to others like me without having to learn a whole raft of features like the ones you would like to see.

If its bells and whistles you want there are plenty of other choices out there with lots to offer for those who are capable of using some of the higher end tools. Atmel Studio and Visual C etc etc...

You have to remember that a lot of us don't have the experience that you do with languages.

My only gripe is the seeming lack of testing before an IDE version is released and I know I am not alone on that issue.

Otherwise don't fix what ain't broken !

pert:
You're going to have to explain these massive problems. I'm not aware of any. Maybe you don't understand how the Arduino IDE library system works?

Have a look at Sketch doesn't find header file. I am having real problems right now and would appreciate a solution.

And, 'No", I do not understand how the Arduino library system works. I have always used header files. I have loaded Arduino libraries using the IDE, they are filed somewhere on 'C' drive, they work, I never see them. I will have a look at the Library Tutorial and see if that solves my problem.

@ vagulus.

May I suggest you go back to your original thread as you were getting better results there.
Either that or suggest a MERGE of the two threads.

Just because you don't like the way the IDE operates at a simple level for everyone else doesn't mean its going to get changed.

Again if you look at the higher end IDE's I am sure you will find one that meets your needs and works more with how you demand it to.
Some of those are even FREE just as this one is.

I noticed that you are maybe using it in an educational environment so maybe the simplicity is too low for that aspect.

Ballscrewbob:
Just because you don't like the way the IDE operates at a simple level for everyone else doesn't mean its going to get changed.

Hey there! Don't get defensive! Have you forgotten that I asked, "How do you Forum members feel about this issue?" I started this thread simply to differentiate this issue from the problem with header files.

I have the Dev-C++ IDE/compiler but it does not recognize the .INO format. Couple that with the fact that the Arduino IDE won't open a .CPP and we are back at an impasse. Your suggestion that*"Again if you look at the higher end IDE's I am sure you will find one that meets your needs and works more with how you demand it to"* doesn't seem to provide a workable solution.

For that matter, I cannot see how having folders forced on you makes programming any easier, and files in one Project folder interact because they, and usually files in sub-folders, are mutually visible.

Its not a bad habit of 1.6.9 its actually most of the versions so the topic line is a bit off to say the least

I am sorry but it seems like you are expecting a simple IDE meant to be easy for the masses to use to be tailored you your requirements just because it does not meet your standard or you want it to follow a higher standard than is actually needed for most beginners who would probably get stumped at the extra complexity that you want.

That despite the fact that there are many many thousands of users who think its the best thing since sliced bread and you seem to be in a minority or seem unprepared to see what others are using.

So my recommendation that you try something a little more upmarket is not as you deem "doesn't seem to provide a workable solution" but in fact would probably provide you with a very workable solution.

I am not getting defensive but noticed that once the other thread started to run out of steam in your favour that you promptly started another thread on pretty much the same topic something that is often frowned upon.

There are other sections within the forum that may be more tailored to the REAL topic you are going on about. Maybe its worth asking over there or looking at some of the other IDE's some of the more advanced programmers use.

Yes I know I am beating my head against a wall trying to suggest you look at something better than the IDE everyone else starts with but trust me you are pushing this topic in the wrong area for a start as its meant for troubleshooting not software requests which you can make on GITHUB or the other sections in here.

vagulus:
My file structure is shown in the attachment.

The attachment doesn't show the "GHTS_Private" folder within the "libraries" folder. It looks like you have "GHTS_Private.h" and "GHTS_Private.cpp" directly in the "libraries" folder. Also, be sure to restart the IDE when you make changes to the libraries.