Arduino 2.0.1 IDE - Howto Load *.h File into NewTab?

Greetings All,

I am on the Arduino IDE v2 learning curve and so far have not found how I can load a header file from an external library folder into a new tab. The ~file/open~ function seems limited to *.ino and *.pde file types.

Yet one sample project I have been studying does loads with a couple of the header files already loaded in additional tabs thus it is clearly possible to have IDE access to different file types. I presume there must be a procedure for loading other file types that I haven't learned about yet.

Many thanks in advance for helpful info!

tma

Tabs can only be used for files in the same folder as the main sketch so if you copy the .h file to the sketch folder then it will appear in a tab. However, if the .h is the header for a library then you will need to move the other library files to the sketch folder

Why do you want an external library .h file in a tab in the IDE ?

At the right hand side in the IDE, click the 3 dots as shown in below image

image

Select new tab and fill in the filename.
image

Click OK

Thanks but this does not provide me directory tree selection for loading the header file which is in the library directory - it just provides an empty file within a new tab.

Thanks for shedding this light!

The reason for viewing the library header file is just for an understanding review of the application code. I could of course load the library file to study in a separate text editor but it would be more convenient to just have it in a separate tab. Seems to me I was able to load library files without moving them into the sketch directory in earlier versions of Arduino but I am not certain. A cautionary restriction makes sense. Certainly any external header files should be write protected.

It is good to know that if I copied the library files into the application directory that they would just appear in new tabs. I didn't understand that before now - thanks!

Arduino IDE is a tool for developing Arduino sketches. This is why the IDE only allows you to open Arduino sketches. As explained, it is possible to add .h header files, .cpp C++ files, .c C files, and .S assembly files to the sketch, however, every sketch must contain at least one .ino file, so that is the file you open to open the sketch.

It is possible to open library files that are used by your sketch in a read-only editor tab. You do this by right clicking on the header filename or code reference from the library in your sketch, then selecting "Go to Definition" from the context menu.

It has never been possible to open the library files alone. There is a hacky technique where you can add a dummy .ino file to the library source folder to make it look like a sketch to the IDE.

The subject was discussed with the IDE developers here:

Many thanks for taking the time to explain this to me!

BTW I had tried highlighting and right clicking the "#include <LoRa.h>" statement and then selected the "Go To Definition" option but it returned "No Definition Found". It may be because my sketch folder is located on a different drive than the Arduino library however the sketch does verify error free as shown below thus the build process can find it:

"Sketch uses 760661 bytes (58%) of program storage space. Maximum is 1310720 bytes.
Global variables use 38424 bytes (11%) of dynamic memory, leaving 289256 bytes for local variables. Maximum is 327680 bytes "

Try this:

  1. Select Sketch > Verify/Compile from the Arduino IDE menus.
  2. Wait for the compilation to finish.
  3. If you see a message "Building sketch" or "indexing: ..." at the bottom right corner of the Arduino IDE window, wait for it to disappear.

Now try the "Go to Definition" procedure again.

The Arduino build system does something called "library discovery" that allows it to automagically find the library for each file in an #include directive (e.g., LoRa.h). With a traditional build system, the user would need to manually configure the paths to libraries, which would make Arduino IDE much less beginner friendly.

That "library discovery" process is somewhat slow/resource intensive due to the need to search through a lot of folders. That does not add any significant overhead to the sketch compilation process. However, Arduino IDE 2.x has a "language server" to enable the code aware features like autocomplete and "Go to Definition". The language server processes the sketch after every change you make to it. We received a number of complaints from users about the resource usage of the Arduino IDE. When the developers investigated this, they identified that running the library discovery process repeatedly for the language server was a significant component of the resource usage. So the developers disabled library discovery during the language server processing of the sketch:

https://forum.arduino.cc/t/arduino-ide-2-0-0-rc9-available-for-download/1014434#deferred-library-discovery-14

This means the language server will not be aware of the library code made available for use in the sketch between the time you add an #include directive and when you compile the sketch. This is why "Go to Definition" for the header files and references to library code may only start working after you compile the sketch

Thanks again for being so helpful and for your excellent explanation!

I am wondering if possibly I have encountered a library discovery process execution bug with my v2.0.1 install? I deleted the "#include <LoRa.h>" line within the source code and then ran "Sketch>Verify/Compile" whilst watching the "Compiling sketch" bottom right popup banner message. I watched until the expected error messages appeared within the "Output" window after the build failure.

I then re-inserted the "#include <LoRa.h>" line back into the source code. Then for the second time I ran "Sketch>Verify/Compile" whilst watching the "Compiling sketch" banner until the build successfully completed error free this time. The banner message went directly from "Compiling sketch" to "done compiling" before disappearing.

During the builds I did not notice any indication of the implementation of a new "library discovery" process although it might have happened in the background as the build times seemed longer.

After both compilation builds the right click on selected "#include <LoRa.h>" line and "Go to Definition" procedure resulted in the same "No definition found" message.

Incidentally I did a system wide search and discovered copies of the "LoRa.h" file in five different locations within my directory tree. They are all recent and the same size thus I presume all the same contents copied from the ..\arduino\librairies path.

If you enable verbose compilation output in the Arduino IDE preferences (File > Preferences), then watch the output printed to the "Output" panel at the bottom of the window while compiling, you will see it shows the discovery process with some output like this:

Detecting libraries used...
"C:\\Users\\per\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Users\\per\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\cores\\arduino" "-IC:\\Users\\per\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\variants\\mega" "C:\\Users\\per\\AppData\\Local\\Temp\\arduino-sketch-047B33093D819EF8F05D624E18F99604\\sketch\\sketch_nov14b.ino.cpp" -o nul
Alternatives for LoRa.h: [SomeLibrary@1.0.0]
ResolveLibrary(LoRa.h)
  -> candidates: [SomeLibrary@1.0.0]
"C:\\Users\\per\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Users\\per\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\cores\\arduino" "-IC:\\Users\\per\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\variants\\mega" "-IC:\\Users\\per\\Documents\\Arduino\\libraries\\SomeLibrary\\src" "C:\\Users\\per\\AppData\\Local\\Temp\\arduino-sketch-047B33093D819EF8F05D624E18F99604\\sketch\\sketch_nov14b.ino.cpp" -o nul
Alternatives for Foo.h: [AnotherLibrary@1.0.0]
ResolveLibrary(Foo.h)
  -> candidates: [AnotherLibrary@1.0.0]
"C:\\Users\\per\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Users\\per\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\cores\\arduino" "-IC:\\Users\\per\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\variants\\mega" "-IC:\\Users\\per\\Documents\\Arduino\\libraries\\SomeLibrary\\src" "-IC:\\Users\\per\\Documents\\Arduino\\libraries\\AnotherLibrary" "C:\\Users\\per\\AppData\\Local\\Temp\\arduino-sketch-047B33093D819EF8F05D624E18F99604\\sketch\\sketch_nov14b.ino.cpp" -o nul

As I said above, the amount of time library discovery takes is small relative to the rest of the compilation process, which you are only running periodically. The problem was that it was happening every few seconds as the language server repeatedly reprocesses the sketch as you type.

Please provide instructions I can follow to reproduce the issue.

I need to know which board you have selected from the Tools > Board menu in Arduino IDE.

I need to know where I can get the library that contains this file LoRa.h.

Please do this:

  1. Select File > Preferences from the Arduino IDE menus.
  2. Check the box next to "Show verbose output during: ☐ compilation".
  3. Click the OK button.
  4. Select Sketch > Verify/Compile from the Arduino IDE menus.
  5. Wait for the compilation to finish.

Now examine the contents of the black "Output" panel at the bottom of the Arduino IDE window. There you will see a list of the libraries used by your sketch and their locations.

For example:

Using library SomeLibrary at version 1.0.0 in folder: C:\Users\per\Documents\Arduino\libraries\SomeLibrary 
Using library AnotherLibrary at version 1.0.0 in folder: C:\Users\per\Documents\Arduino\libraries\AnotherLibrary 

This information may be able to help you to tell me where I can get the library with the LoRa.h file in it.


"Go to definition" does not work for any of the "#include *.h" files thus it does NOT appear to be a "LoRa.h" file specific issue.

It seems the problem may be associated with the editor right click selection copy process or it simply cannot find the path as:

  • If I highlight "LoRa.h" then it states "No definition found for 'h' "
  • If I highlight "<LoRa.h>" then it states "No definition found "
  • If I highlight the whole line "#include <LoRa.h>" it also states "No definition found "
  • If I highlight a different whole line for a different header file for example:
    "#include "ds3231.h" - it also echoes "No definition found "

The LoRa.h file is in the usual Arduino libraries location but it seems to have been copied to a few other locations by the build process. In my case it is:

C:\Users\tma\Documents\Arduino\libraries\LoRa

In my case my sketch ino file is buried pretty deep, well down the directory tree in a separate drive:

D:\TMA\ArduinoSketchbook\ESP32 TTGO LoRa32\TTGO_LoRa-Series\TTGO-LoRa-Series-master\LoRa


Clearly the compiler can find the file as otherwise there would be errors. This is roughly the LoRa.h statement I got from my compiler verbose Output window (note that this editor stripped some of the "*" rem characters off):

"C:\Users\tma7t\AppData\Local\Temp\arduino-sketch-EEDADB51974E1AADB21CFC42870C301F\sketch\LoRa.ino.cpp" -o nul
Alternatives for LoRa.h: [LoRa@0.8.0]
ResolveLibrary(LoRa.h)
-> candidates: [LoRa@0.8.0]
..........................................

I hope this info is helpful.

Well this is embarrassing!!! The problem has become corrected by the unexpected occurrence of a hydro utility power failure and reboot (I normally leave my computer on 24/7, most of the time in sleep mode). Now the right click context procedure is working OK. It appears to have been caused by a mysterious Windows 10 glitch that disappeared with a reboot.

I did re-start the Arduino IDE app a couple of times to no avail but it never occurred to me that the cause might have been due to an operating system mysterious glitch that didn't affect the compiler build procedure yet impacted the IDE, gosh!

With hindsight had I had previous experience with using the "Go to definition" feature successfully and had I not been using a new IDE version for the first time I might not have gone so far down this garden path, :blush:

Many thanks again for the help! The positive side for me is that I learned quite a bit.

tma

You are welcome. I'm glad it is working now.

Regards,
Per

The W10 problem was sure subtle! I also use this i7 PC for my routine computing. During the week prior to yesterdays utility power failure it was alternately used with 3 different browsers, email, word processing, security utilities, text editor, spread sheet, journal, etc, etc. There were no signs of any operating system issue. When it booted up it did load a Windows update which has me wondering.

Best Regards,
tma

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