Project not picking up lib_extra_dirs from platformio.ini

I’m using a clean install of MacOS Catalina (long story) and I’ve done a clean install of Homebrew and CLion. I installed PlatformIO using Homebrew, then I installed the PlatformIO Plugin into CLion.

I create a new project, then I always modify my Platformio.ini file to include some folders where the libraries I need are located.

However, when I create a new project, the Arduino.h library isn’t included in the project (no code completion etc.). And when I try to add the folder to Platformio.ini, it won’t pick it up. HOWEVER, if I include Arduino.h by typing out the full path to the library, it works just fine, with code completion etc.

So obviously, my lib_extra_dirs in Platformio.ini isn’t informing the project that those folders are searchable locations for library #include statements…

And YES, I did use Tools, PlatformIO, Re-Init after making the change to Platformio.ini

Any ideas why this isn’t working?

Here is my Platformio.ini just to be thorough:

[env:nanoatmega328new]
platform = atmelavr
board = nanoatmega328new
framework = arduino
lib_extra_dirs = /Users/michael/Documents/Arduino/libraries
             /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino
             /Applications/Arduino.app/Contents/Java/libraries
lib_ldf_mode = chain+
lib_compat_mode = soft
upload_port = /dev/cu.usbserial-14110
upload_flags =
    -V

So this DOES NOT WORK:
#include <Arduino.h>

While this DOES work:
#include </Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h>

I’m stumped

Arduino in this sense is not a library but the framework, or core. No lib_extra_dirs directives must be used to include the Arduino core, that is already done by framework = arduino. You should remove the last two entries of lib_extra_dirs and the first one as well, in favor for lib_deps.

Unreproducable. Creating a new project with the PlatformIO CLion plugin installed, using New → Project → PlatformIO,

Autocomplete comes up immediately in the newly created project.

I would suggest to just use the platformio.ini

[env:nanoatmega328new]
platform = atmelavr
board = nanoatmega328new
framework = arduino
upload_port = /dev/cu.usbserial-14110
upload_flags =
    -V

with a minimal cpp file of

#include <Arduino.h>
void setup() {
// write your initialization code here
}

void loop() {
// write your code here
}

Then Tools → PlatformIO → ReInit and Tools → PlatformIO → Build.

If it does not build, something is broken.

Then to be safe, right-click on the project and “Reload CMake project”

Then check if External Libraries → Header Search Paths → arduino → Arduino.h file shows up.

grafik

If yes, Autocomplete ought to work.

I figured it out …

When I go into CLion Settings, under Build, Execution, Deployment, I had an entry under CMake called Debug

The reason I looked here, was because when I tried to build a project, it kept saying:
Error: Unknown environment names 'Debug'. Valid names are 'nanoatmega328new'

So under CMake, I created a profile that matched the name of the section in Platformio.ini

[nanoatmega328new]

and then I was able to build a project … then I thought, “I wonder if the inclusion works now” and when I took away the path to an included library, sure enough, it picked it up just fine.

I appreciate the detail in your response. You did teach me some things that I didn’t previously know about PlatformIO and that is definitely appreciated! So thank you for taking the time to write this reply.

Mike

Okay good that it’s working now.

Just for completeness: The documentation mentions that. You can just remove all CMake profiles / environments and press the “+” button and it will fill it with the correct details. This also works for multiple environment entries in the platformio.ini

E.g.

[env:nanoatmega328new]
platform = atmelavr
board = nanoatmega328new
framework = arduino

[env:uno]
platform = atmelavr
board = uno
framework = arduino

And after Tools → PlatformIO → Re-Init and opening the CMake settings again, removing all previous environments and clicking “+” two times:

The correct environments are all there and can be switched nicley from the environment selector in the top right corner of CLion.