Notifications
Clear all

Adding Libraries in PlatformIO (VS Code)

20 Posts
3 Users
0 Likes
866 Views
ronpenrose
(@ronpenrose)
Member
Joined: 1 year ago
Posts: 25
Topic starter  

Transitioning from Arduino IDE to VS Code and PlatformIO. I have viewed the DroneBot video.

I am having frequent issues adding Libraries to projects. Sometimes all works fine but other times I get errors on a library install to a project.

Frequently, after adding a library to a project I get the squiggly line under the include with error message "cannot open source file ...."

Here is most recent example:

I have code from Bill's video on OLED's. The sketch requires the following includes:

  • #include<Adafruit_GFX.h>// Core graphics library
  • #include<Adafruit_TFTLCD.h>// LCD library
 
GFX installs fine but not Adafruit_TFTLCD.h
 
I have also loaded the code in Arduino IDE and that library installs fine and the sketch compiles fine.
 
I have inspected the pio folder in the project and both library folders are there. I have also looked at the .ino file and it shows GFX and Adafruit_TFTLCD paths.
 
 
This topic was modified 5 months ago by ronpenrose

Ron Penrose


   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

Maybe try "" instead of <>. I know that's crazy, but you never know.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
ronpenrose
(@ronpenrose)
Member
Joined: 1 year ago
Posts: 25
Topic starter  

@zander That worked! I have not figured out the difference between "" and <> but now, I will try that every time I get similar error. Thanks very much.

Ron Penrose


   
ReplyQuote
ronpenrose
(@ronpenrose)
Member
Joined: 1 year ago
Posts: 25
Topic starter  

@zander 

I spoke too soon. I still get the error.

Ron Penrose


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

@ronpenrose Unprintable character? Try the arduino IDE, if it works the issue is with VScode. If the arduinbo IDE fails, comment out that line and goto menu Skecth - Include Library now select the library you want and see what happens. If it works in the IDE, go try it in VS.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1684
 

Hi @ronpenrose,

  I don't know if it applies to the specific editor/IDE you have, but usually "" and <> each have specific search path rules, and they do not always seem to match where the relevant file is located.

 As a start, I would try a fully specified path like "C:\MyLibs\fredlib.h\fred.h" or equivalent, depending upon which operating system you are using. That way, it shouldn't matter whether the paths have the right directories or not, but should establish if this is the issue.

Of course, this is an ugly solution, which may be good enough for a one-off, but if it works, then start trying to track down the search paths, and fix the problem more permanently.

Hope this helps you move forward .. you might like to provide some feedback to the thread, for further discussion.

Best wishes and good luck, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

@davee @ronpenrose Sorry to disagree Dave, but the path won't look anything like that, and it is different for each of the supported platforms (Win, Mac, Linux). It would be wiser to use the C and C++ standard syntax. Here is the info on #include syntax and how it searches from the Arduino.cc Reference manual. https://www.arduino.cc/reference/en/language/structure/further-syntax/include/

The "#include xyz.h" is the most versatile as it searches first your sketch folder and THEN the standard library folders. HOWEVER, it is a sharp knife since you can place a library include in your sketch folder to override the standard library include. This may be required in some rare instances (I may have seen one in my 65 years of coding)  but like all sharp knives, it is best left to the experts lest you don't mind spilling a lot of your own blood.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
ronpenrose
(@ronpenrose)
Member
Joined: 1 year ago
Posts: 25
Topic starter  

@davee Thanks. I will look into this.

Ron Penrose


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1684
 

Hi Ron @zander and @ronpenrose,

  Thanks, Ron for your alternative suggestion of copying the file into the sketch folder which should also be a valid workaround, and is one I have used in the distant past. I think both suggestions should also be replaced with a better solution at first convenient moment, but appreciate it may be little tricky to track down.

Copying the .h file to the local workspace can get messy if several .h files are affected, and also, if the is part of a library that subsequently gets updated, the copied file will not get updated at the same time. By contrast, setting a full path to the file in the original place should avoid these downsides.

-----------------------------

Apologies if my way of describing the workaround was confusing, when I said:

I would try a fully specified path like "C:/MyLibs/fredlib.h/fred.h" or equivalent, depending upon which operating system you are using.

Of course, this is the Windows version, and Linux or an Apple operating system will be different in detail, which is why I included the second half of the sentence, assuming the @ronpenroser would be familiar with the format for his computer system. I also assumed that most people, even if they do not currently use Windows, will have met the format and recognise what I meant. Apologies, if my assumptions were inaccurate.

-----------------------------------------------------------------------------------------------------

Similarly, I agree the short form like #include "fred.h", is by far the preferred form, but reading through the messages on this thread suggested that both the "" and <> forms had been tried without success.

Hence, I suggested trying the fully specified path form to see if it worked. I also noted, that if it worked, then it should only be regarded as a 'quick fix' which identified (or otherwise) the problem, but it could be used to avoid getting 'bogged down' in the details at an inconvenient time.

--------

If the problem turns out to be that PlatformIO is not looking in the right place, then I think that piece of information is potentially very useful, because it suggests questions to Google that are more specific to the problem, along the lines of "Platformio: Failing to find included .h file" or "How to make Platformio search the correct directories for include .h files", which will reveal this is not a new problem for many, and hopefully, also some answers.

One answer I glanced at suggested a method of telling Platformio to list the files and associated full paths it did find. Comparing those with the location of the one that it is being reported missing might suggest an answer, including the possibility that  the missing .h file has been loaded onto the wrong place ..

try reading https://community.platformio.org/t/view-all-included-files/4320/2

-------------------------

I hope this helps. Best wishes, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

@davee @ronpenrose Sorry, I did not suggest copying the affected .h file into the sketch folder, I was pointing out the danger of using the "" local file search vs the <> system library search as specified in https://www.arduino.cc/reference/en/language/structure/further-syntax/include/

What I did suggest is to first try the Arduino IDE in order to determine if this is caused by platform IO or is something else (like an unprintable character)

Although short term solutions like using full paths or moving system files into local folders may work, these are obviously horrible and non-strategic solutions for the long run.

I spent a good deal of my 65 yr career tracking down and fixing problems like this all over the globe. I would have only given myself 1 out of 10 points for solutions like full path or localizing a system file. It is always better to find the underlying problem and fix it rather than prolong the problem by 'just making it work'.

Since platformIO/vsource is such a complex environment it is pointless for me to try it or that is what I would do. Hopefully @ronpenrose will try the arduino IDE and report back.

BTW, the unprintable character that was the root cause of a similar issue many decades ago was the back space character 0x08. I thought at the time it would be very tricky to include that character in a password  so even someone seeing the result would be fooled. I have no particular reqason to suspect that is what is happening here, it is far more likey to either be a PlatformIO/VS issue, or a simple 0O 1l mixup. Depending on font used the l1 (lowercase letter L vs the digit 1) can be very hard to spot.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

@davee I forgot to mention, you can also show the locations of included files in the arduino IDE with the verbose option. See pic. Just FYI but if the arduino IDE is working, then the bug is in VS/PlatformIO.

Screenshot 2023 12 13 at 23.05.24

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
ronpenrose
(@ronpenrose)
Member
Joined: 1 year ago
Posts: 25
Topic starter  

@zander I have attached some screens of the project files that may be helpful. It seems all full paths are correct.

 

Project Libraries Installed

 

Project Code

 

Project Properties Json

 

Project INI

Ron Penrose


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

@ronpenrose Ok. I don't use that beast, I can do everything with the Arduino IDE.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
ronpenrose
(@ronpenrose)
Member
Joined: 1 year ago
Posts: 25
Topic starter  

@zander LOL. I tried to use it a year ago and gave up with this library inconsistency issue. After watching the video, I thought I would try again. I use Visual Studio and like the intelligence and other features. I'm getting close to giving up again!

Ron Penrose


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

@ronpenrose What exactly do you mean by intelligence, the Arduino IDE 2.x.x has a lot. I can't think of anything I miss vs my professional IDE I used when I was paid to code other than a debugger but I don't really need a debugger for a few hundred lines of code like I did when I was working with 10's and even 100's of KLOCs.

Just to put things in perspective I was first trained on the hardware (IBM) firmware (we called it something else) then the OS. IIRC, the printout of the OS would have stretched to the moon at least. There were no aids in those days, just core dumps. assembler was a high level language to me.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Page 1 / 2