How to remove .h and .cpp from ide tabs

At the top of my programming window, there are three tabs. One has the name of the file I am programming in. The other two are libraries. one a .h, and the other a .cpp.

When compiling the program, it gives a ton of errors culminating in "Error compiling for board Arduino/Genuino Uno." all of the errors are related to the other two tabs (the .h and .cpp).

I no longer use the libraries (might in the future).
But I do not see a way to get rid of them.
I quit the ide. I dragged the unneeded libraries out of the arduino folder. Restarted. The tabs are still there.

I then deleted the contents of the .h and .cpp tabs. Now the tabs are empty.
My program compiles just fine.

What is going on?

Thanks!!

Whenever you open a .ino file, it will automatically open any other files in the same folder. Somehow your "move" didn't work and the IDE still thought that the files were in that folder. What does the folder look like when you use the regular file explorer?

This is why each Arduino sketch must have its own folder.

The .h and .cpp files reside in the sketch directory. So you can delete them from there using your operating system's tools. Restart the IDE after that.

There is also a little down arrow in the IDE at the right hand side of the border containing the tabs. Click it and choose delete (after you have selected the correct file).

The above explaination worked. I sorted out my sketch folder.

However ...
My sketch folder has only the sketch file in it. It has an include statement for a DHT.h sensor library. That library is not in the sketch folder. It is in the Arduino library folder, as well as another folder at the same level as the sketch folder. Does the library folder need to be in the sketch folder? The library folder has a .cpp file, libraryProperties, a readme, etc. Are any of these needed? Can I delete all library folder copies except the one in the Arduino library? what is best practice?

Thanks!
Ted

The #include directive can be used two ways. Using angle brackets <> tells the compiler to go looking in the standard library locations first. Using quotes “” tells it to go looking in the sketch’s local folder first.

For libraries that are used in more than one sketch, you should only ever have one copy, in the standard location. Delete all other copies.

C:\Users\your username\Documents\Arduino\libraries (under Windows) is the location where your additional libraries go (e.g. those that you downloaded). Those are always compiled regardless if they are used or not; if they are not used, they will not be included in the final resulting file.

Removing them makes life complicated because you might need some in one project and some in another project and keep on deleting / adding them depending on needs.

In general I agree that it’s best to just have a single copy of each installed library in the {sketchbook}/libraries folder. I do this will all of my personal projects. However, occasionally it can be useful to include libraries in the sketch folder. This allows the sketch to be self contained and ensures that a specific or modified version of the library will be used by the sketch. This is very helpful if you’re sharing a sketch that requires a library not included with the Arduino IDE. It can get pretty messy if you just dump all the library files directly in the sketch root folder so it’s usually best to leave each library in their own folder. To do this with recent versions of the Arduino IDE you must put the library folders in a subfolder of the sketch folder named src and modify the include paths in the sketch(and possibly the library if it wasn’t written correctly) accordingly. For example:

Change:

#include <DHT.h>

to:

#include "src/DHT/DHT.h"

Even if you are not using an IDE version recent enough to require the use of the src folder, you may want to use that folder structure anyway to provide for forwards compatibility.

@pert
Thanks for that.

Just in case for others: tested with 1.6.6 and 1.6.7 and that works so I guess newer will also work.