I broke the IDE

So I moved a couple of library files to the sketch folder, so I could see them in the IDE tabs. By all accounts, this seems to be OK, and it worked great for a couple of projects. Until it didn't. Now the complier gives, as an example, the "ArduinoMqttClient.h: No such file or directory" error. (It can't find library files.) I've double checked the usual suspects - spelling/case errors, file suffix is actually correct, and so on. I'm not asking for help solving the problem, as plenty of people have asked that. Here's my question: Does anybody know how the IDE / compiler actually works when it looks for library files? Alternatively, is there some other way to keep the library files visible in the IDE tabs? That doesn't seem like such a big ask to me, but maybe I'm wrong. That's really all I'm after. Not a professional coder, so please straighten me out if I'm way off base here.

I will start by asking why you want to see the library files in the IDE ?

When the files are in the sketch folder how exactly are you #including them ?

  1. Win10. , IDE 2.2.1
  2. wanting lib files visible/accessible so I can easily refer to them & make minor modifications.
  3. #include <ArduinoMqttClient.h> (as an example). That worked on the last two projects, and I'd hoped to avoid calling out the whole path in the #include line.

That will not look in the sketch folder before looking in the standard library locations

Use #include "ArduinoMqttClient.h" to force the compiler to look in the sketch folder first

And, Blammo - that's the solution. After reading ~half of a C++ book, I hadn't seen that detail - Thanks so much to UKHeliBob!!
image
Are there other delimiters that go in that position that I need to be on the lookout for? Either way, I'll read up on preprocessor directives, and hopefully that's a mistake I won't make again. Thanks again - so much!!

The only delimiters are < > and " "

Using < >, the library search looks in the libraries folder of your sketchbook for user installed libraries, the libraries folder of the target board for board specific variants of libraries and in the Arduino installation folder for built in libraries

Thanks again. Good concise explanation of that search order; glad to have it.
Cheers

I suspect that that is a caching issue but I'm not sure. If so, you did compile the two projects that it worked for at least once with the original file location before you moved the library files. The cache is stored in 'C:\Users\yourUsername\AppData\Local\Temp\arduino\sketches' (note that the AppData folder is usually hidden, you will have to make it visible in view → options in Windows Explorer).

To figure out if caching is indeed the cause

  1. Move the library back to the libraries folder.
  2. Start a new project that uses that library, save it and compile it.
  3. Move the library to the sketch directory.
  4. Empty the cache (this is a safe operation, no worries).
  5. Compile again (without changing the <> to "").

You already got the information you needed, but in case you (or others who find this topic while researching related subjects) are interested in the boring details, there is some documentation about the library discovery process here:

https://arduino.github.io/arduino-cli/latest/sketch-build-process/#dependency-resolution

Note that this information is not directly relevant to your use case because the files are not really a library in the sense the term is used in the Arduino world (i.e., reusable code packaged in a manner that allows it to be shared between multiple projects) once you move them to the sketch folder.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.