Ability to open library source in IDE?

I have written a class and tested it gotten it to work. I created the .cpp and .h files as new tabs in a test sketch. When it was done, I moved it to the /libraries folder.

I am able to include the class in another sketch and compile it.

However, now that the .cpp and .h files are no longer tabs in a sketch, I cannot figure out how to open the source to edit it in the IDE. I found an old (11 years!) post on here saying the solution was to use notepad++. Am I to understand there is no way to edit the source of my library files in the IDE?

Typical:
#include <library_name.h>

Forced:
#include "C:\Users\uname\Arduino\libraries\library_name.h"

To edit, just copy the files back into your sketch folder, restart the IDE, and the ,cpp and .h are editable.

Keep in mind that if you do that, you are only including the header file. It will not cause the library source files to be compiled as is the case with the "typical" snippet you shared. So the "forced" snippet is only useful in the case where all the code you need is in the header.

1 Like

Sure, but then I need to keep copying it back and forth between the test sketch folder and the libraries folder to edit and test vs. use globally. Pretty klunky.

1 Like

Also, once I had removed the tabs for the class files from the sketch, I didn't see a way to add them back using the existing files. The only way I saw to add a tab created a new file.

To my knowledge there isn't. So you'll have to move them back to the sketch directory using the operating system.

I say 'move' because that way there is no chance that the IDE uses the wrong one for compiling.

//edit
For IDE 1.8.x, you have to restart the IDE to make them show also it will see them for compiling; not sure how IDE 2.0 handles this

Arduino IDE is a tool for developing sketches. It was never intended to be used for editing libraries.

That said, if you can make the sketch appear as a library to Arduino IDE, then you can edit the library with Arduino IDE. You already did something like this when you had the library files in your sketch. The part you missed is that you can put that sketch under the normal library installation location (the libraries subfolder of the Arduino sketchbook folder), where it can be used as a library while also being editable as a sketch. This is a bit of a hack, and not an officially supported use case, but it does work.

  1. Add a file with a .ino file extension to the folder containing the library files you want to edit with Arduino IDE. The filename must match the folder name (e.g., if the folder is named FooLib, then the file must be named FooLib.ino).
    This file allows Arduino IDE to open the library source files as if they were parts of a sketch.
    This file will not actually be compiled as part of the library. It doesn't matter what the file contains. I use it as a place to store my "to do" list for the project. You could also use it as a test sketch for the library, in this way you can actually compile the library right from the same IDE window where you are editing it instead of having a sketch open in a separate IDE window.
  2. Add a file named .development to the root of the library folder.
    This file is necessary because otherwise Arduino IDE treats the contents of the library as read-only (to prevent people from inadvertently modifying the example sketches).
    The file can be empty. Arduino IDE only checks whether or not it is present.
  3. If it doesn't have one already, add a file named library.properties in the root of the library folder.
  4. Open the library.properties file in any text editor.
  5. Add the required data to the file, following the documentation here:
    https://arduino.github.io/arduino-cli/latest/library-specification/#library-metadata

Now open the .ino file you created at step (1) in Arduino IDE. You will see each of the library code files from the same folder in the Arduino IDE editor as tabs and you will be able to edit the code in those tabs.

I used Arduino IDE for Arduino development some years ago, but these days I prefer to use a standard development editor such as VS Code instead, using Arduino IDE only for real sketches as it was intended.

1 Like

Well, IMO, a library implies completely tested code. /libraries is a location the IDE uses for 3rd party libraries, so that is updated by the IDE and indexed by the IDE. Get your code working correctly from the sketch folder then transition same to the /libraries.

I never put my own libraries into /libraries, I keep them in the sketch folder so that I can easily Zip up the folder as backup.

I certainly know how to move files around using the operating system; I was talking about restoring the tabs in the editor that give you access to editing them.

Restarting the IDE did that, thank you.

I never put my own libraries into /libraries, I keep them in the sketch folder so that I can easily Zip up the folder as backup

I can see that. However, that implies that you never:

  1. Want to continue developing libraries, creating new versions
  2. Use those new versions globally, rather than in just one sketch.

Suppose I have developed and tested a library, and want to make it available to multiple sketches.

Then, at some point, I figure out a way to perform some function more efficiently. I want to be able to modify the library in one place (/libraries) and have that change available to every sketch that uses it.

Otherwise I have to copy the files back to sketch folder...make the modification and test it...move them back to /libraries....

2 Likes

Thank you, this is essentially what I ended up figuring out. Strangely though, I didn't have to add a .development file; the IDE still allows me to edit the library files.

I'll check out VS Code, thanks.

Create an empty .ino file inside the directory containing your library source with the same as the directory (yes, even 'src.ino' if your sources are in a 'src' sub-directory). Open that .ino and your library files will show up as tabs in the IDE.

You are being difficult; just copying a few files into a new sketch folder will not ruin your life. If it does, you need another hobby.

Hard disk space is cheap and the concept of minimizing copies of files is not a major concern. By localizing files to a sketch folder, you can evolve your library without concern that past programs must be revisited and re-tested. Some development environments like Cypress forces all libraries to be copied and bound into a single project.

1 Like

Thank you, John. That's basically what I ended up doing. Sorry for the dumb question.

Sorry you feel that way. Several other users have provided a good solution rather than chiding me.

1 Like

Are you using Arduino IDE 2.x? The instructions I shared above were intended to work for Arduino IDE 1.x and 2.x both. The addition of the .development file and library.properties files to allow editing of library files is currently only required when using Arduino IDE 1.x to edit the library.

I thought about adding that information in my previous reply, but since it doesn't cause any harm in Arduino IDE 2.x and there is a plan to eventually emulate the .development file system of Arduino IDE 1.x in 2.x (arduino/arduino-ide#936) and I wanted the information to continue serve as a reference into that future, I decided to leave it out.

The nice thing about VS Code is the Eclipse Theia IDE framework Arduino IDE 2.x is built on is somewhat based on VS Code, including the UI design, so you will find quite a bit of consistency between the UI of the two applications.

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