CodeBlocks: can't locate library managed by PIO

To reproduce:

  1.   mkdir ./test1
     [az@dell5000 MQTT_1]$ cd test1
     [az@dell5000 test1]$ ~/.platformio/penv/bin/pio project init --ide codeblocks --board esp32dev
    
     The current working directory /home/az/Work/Arduino/MQTT_1/test1 will be used for the project.
    
     The next files/directories have been created in /home/az/Work/Arduino/MQTT_1/test1
     include - Put project header files here
     lib - Put here project specific (private) libraries
     src - Put project source files here
     platformio.ini - Project Configuration File
    
     Project has been successfully initialized including configuration files for `codeblocks` IDE.
    
  2. open CB, add new main.cpp :

    #include <Arduino.h>

    void setup() {
    Serial.println(“Ta Da”);
    }

    void loop() {
    //noting
    }

  3. CB build//run . All works.

  4. Add ArduinoJson to platformio.ini:
    [env:esp32dev]
    platform = espressif32
    board = esp32dev
    framework = arduino
    lib_deps =
    GitHub - jandelgado/esp32-aws-iot: Use AWS IoT with the ESP32

  5. close CB;
    ~/.platformio/penv/bin/pio project init --ide codeblocks

    The current working directory /home/az/Work/Arduino/MQTT_1/test1 will be used for the project.

    The next files/directories have been created in /home/az/Work/Arduino/MQTT_1/test1
    include - Put project header files here
    lib - Put here project specific (private) libraries
    src - Put project source files here
    platformio.ini - Project Configuration File

    Project has been successfully updated including configuration files for codeblocks IDE.

  6. Open the project in CB. Open main.cpp:
    #include <esp32_aws → does NOT autocomplete
    #include <AWS_IOT.h> → doesn’t NOT autocomplete ( taken from examples esp32-aws-iot/examples/pubSubTest at master · jandelgado/esp32-aws-iot · GitHub )

BUT somehow it finds the AWS_IOT class…

  1. repeating the procedure:

adding another lib to platform.ini and "init"ng the project:
lib_deps =
GitHub - jandelgado/esp32-aws-iot: Use AWS IoT with the ESP32
ArduinoJson

Main.cpp:
#include <AWS_IOT.h>
#include <ArduinoJson/ArduinoJson.h>


void setup() {


Serial.println("Ta Da");
StaticJsonDocument<200> doc;
doc["hello"] = "world";
}
  1. build:

    Dependency Graph
    |-- 1.0.0 #c2f1f97
    |-- 6.16.1
    Building in release mode
    Compiling .pio/build/esp32dev/src/main.cpp.o
    src/main.cpp:4:37: fatal error: ArduinoJson/ArduinoJson.h: No such file or directory
    compilation terminated.
    Compiling .pio/build/esp32dev/libc6e/ESP32AwsIotCore/aws_iot_jobs_json.c.o
    Compiling .pio/build/esp32dev/libc6e/ESP32AwsIotCore/aws_iot_jobs_topics.c.o
    *** [.pio/build/esp32dev/src/main.cpp.o] Error 1
    Compiling .pio/build/esp32dev/libc6e/ESP32AwsIotCore/aws_iot_jobs_types.c.o
    ========================== [FAILED] Took 2.02 seconds ==========================
    Process terminated with status 1 (0 minute(s), 2 second(s))
    1 error(s), 0 warning(s) (0 minute(s), 2 second(s))

Will appreciate any help.

What happens if you change this to
#include <ArduinoJson.h>

i.e. remove the path. ??

If i remove the full path PIO locates and builds the file:

platform run --target clean 
...
[az@dell5000 test2]$ cat ./src/main.cpp
#include <Arduino.h>
#include <AWS_IOT.h>
#include <ArduinoJson/ArduinoJson.h>

AWS_IOT honrbull ;

void setup() {
honrbull.connect()
Serial.println("Ta Da");
StaticJsonDocument<200> doc;
doc["hello"] = "world";
}
void loop() {
//noting
}

az@dell5000 test2]$ platformio run 
Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
-----------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 1.12.4 > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 3.10004.200129 (1.0.4) 
 - tool-esptoolpy 1.20600.0 (2.6.0) 
 - toolchain-xtensa32 2.50200.80 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 28 compatible libraries
Scanning dependencies...
**Dependency Graph**
**|-- <ESP32AwsIotCore> 1.0.0**
Building in release mode
Compiling .pio/build/esp32dev/src/main.cpp.o
Generating partitions .pio/build/esp32dev/partitions.bin
src/main.cpp:7:37: fatal error: ArduinoJson/ArduinoJson.h: No such file or directory
compilation terminated.
Compiling .pio/build/esp32dev/lib30f/esp32-aws-iot/AWS_IOT.cpp.o
Compiling .pio/build/esp32dev/lib30f/esp32-aws-iot/aws_iot_jobs_interface.c.o
*** [.pio/build/esp32dev/src/main.cpp.o] Error 1

[az@dell5000 test2]$ ls -l ./lib/
ArduinoJson/   esp32-aws-iot/ README         
[az@dell5000 test2]$ ls -l ./lib/ArduinoJson/
total 132
-rw-rw-r--  1 az az   894 Aug 13 18:30 appveyor.yml
-rw-rw-r--  1 az az   117 Aug 13 18:30 ArduinoJson.h
-rw-rw-r--  1 az az 32515 Aug 13 18:30 banner.svg
-rw-rw-r--  1 az az 33770 Aug 13 18:30 CHANGELOG.md
-rw-rw-r--  1 az az   430 Aug 13 18:30 CMakeLists.txt
-rw-rw-r--  1 az az    33 Aug 13 18:30 component.mk
-rw-rw-r--  1 az az   318 Aug 13 18:30 CONTRIBUTING.md
drwxrwxr-x 12 az az  4096 Aug 13 18:30 examples
drwxrwxr-x  6 az az  4096 Aug 13 18:30 extras
-rw-rw-r--  1 az az   900 Aug 13 18:30 keywords.txt
-rw-rw-r--  1 az az   816 Aug 13 18:30 library.json
-rw-rw-r--  1 az az   669 Aug 13 18:30 library.properties
-rw-rw-r--  1 az az  1126 Aug 13 18:30 LICENSE.md
-rw-rw-r--  1 az az  9850 Aug 13 18:30 README.md
drwxrwxr-x  3 az az  4096 Aug 13 18:30 src
-rw-rw-r--  1 az az   871 Aug 13 18:30 SUPPORT.md

removing the path:

[az@dell5000 test2]$ head ./src/main.cpp

#include <Arduino.h>
#include <AWS_IOT.h>

//#include <ArduinoJson/ArduinoJson.h>
#include <ArduinoJson.h>

AWS_IOT honrbull ;

void setup() {
[az@dell5000 test2]$ platformio run --target clean
Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
-----------------------------------------------------------------------------------------------------------
Removed /home/az/Work/Arduino/MQTT_1/test2/.pio/build/esp32dev/partitions.bin
Removed /home/az/Work/Arduino/MQTT_1/test2/.pio/build/esp32dev/.sconsign37.db.dblite
Removed /home/az/Work/Arduino/MQTT_1/test2/.pio/build/esp32dev/lib30f/esp32-aws-iot/AWS_IOT.cpp.o
Removed /home/az/Work/Arduino/MQTT_1/test2/.pio/build/esp32dev/lib30f/esp32-aws-iot/aws_iot_jobs_interface.c.o
Done cleaning
======================================= [SUCCESS] Took 0.52 seconds =======================================
[az@dell5000 test2]$ platformio run 
Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
-----------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 1.12.4 > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 3.10004.200129 (1.0.4) 
 - tool-esptoolpy 1.20600.0 (2.6.0) 
 - toolchain-xtensa32 2.50200.80 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 28 compatible libraries
Scanning dependencies...
**Dependency Graph**
**|-- <ESP32AwsIotCore> 1.0.0**
**|-- <ArduinoJson> 6.16.1**
Building in release mode
Compiling .pio/build/esp32dev/src/main.cpp.o
Generating partitions .pio/build/esp32dev/partitions.bin
Compiling .pio/build/esp32dev/lib30f/esp32-aws-iot/AWS_IOT.cpp.o
Compiling .pio/build/esp32dev/lib30f/esp32-aws-iot/aws_iot_jobs_interface.c.o
Compiling .pio/build/esp32dev/lib30f/esp32-aws-iot/aws_iot_jobs_json.c.o
Compiling .pio/build/esp32dev/lib30f/esp32-aws-iot/aws_iot_jobs_topics.c.o
Compiling .pio/build/esp32dev/lib30f/esp32-aws-iot/aws_iot_jobs_types.c.o
Compiling .pio/build/esp32dev/lib30f/esp32-aws-iot/aws_iot_json_utils.c.o
Compiling .pio/build/esp32dev/lib30f/esp32-aws-iot/aws_iot_mqtt_client.c.o
Compiling .pio/build/esp32dev/lib30f/esp32-aws-iot/aws_iot_mqtt_client_common_internal.c.o
src/main.cpp: In function 'void setup()':
src/main.cpp:12:18: error: no matching function for call to 'AWS_IOT::connect()'
 honrbull.connect()
                  ^
In file included from src/main.cpp:3:0:
lib/esp32-aws-iot/src/AWS_IOT.h:39:9: note: candidate: int AWS_IOT::connect(const char*, const char*, const char*, const char*, const char*)
     int connect(const char *hostAddress, const char *clientID, 
         ^
lib/esp32-aws-iot/src/AWS_IOT.h:39:9: note:   candidate expects 5 arguments, 0 provided
*** [.pio/build/esp32dev/src/main.cpp.o] Error 1

The issue is with CB integration:
in CB when i type ::
#include <ArduinoJ → CB autocompletes to

the correct path is ./lib/ArduinoJson/ArduinoJson.h"
If i try this example serializeJson() | ArduinoJson 6

StaticJsonDocument<200> doc;
doc["hello"] = "world";
serializeJson(doc, Serial);

the autocomplete does not see “StaticJsonDocument”:

P.S. I just noticed that in this update i used the “project/lib” as a test case, whereas this thread started as lib_deps issue of CB not autocompleting. Upon repeating the tests, i see no difference in the CB/PIO behavior:

  • CB provides the “full” path to the H file - e.g. ArduinoJson/ArduinoJson.h, which breaks PIO compile operation

  • CB doesn’t “see” StaticJsonDocument, though it is specified in ArduinoJson/Document/JsonDocument.hpp. I randomly checked and JsonDocument is also not visible for autocompletion .

That’s what I thought might happen… as the C++ compiler knows about the specific .h files … not the folders they are in… so specifying the path (in any form) will generally break the compile (since "ArduinoJson/ArduinoJson.h" != "ArduinoJson.h", etc.)

So the question then is why does CodeBlocks incorrectly put it in! :open_mouth: :slightly_frowning_face: If I get a chance later today I’ll install it and see if I can figure anything out.

Edit: So CodeBlocks is up and running, and I’m trying it against the ArduinoJson library. Same problem - the CB autocomplete won’t suggest StaticJsonDocument, but does compile fine.

image

I tried adding EasyButton and re-init’ing the project. CB didn’t suggest the include when i was typing it, but as soon as it had been added, it recognised it when I was adding bits in…

image

… so perhaps the complexity of the ArduionJson library is too much for CBs autocomplete? I tried the same project with VSCode, and its auto-complete service was recognising all the various bits of ArduionJson, so as I’ve not used CB in several years (and then, only for desktop C++ code), I’m not sure what’s going on.

hmm. interesting indeed.
what config files PiO produces for CB and VSCode ?

I’ll have load the Windows VSCode file later, as I’m on linux atm, and off for the night in a few minutes. However, if you take into account that E: and /media/2TB_upper/ are the same drive, just seen differently by different OSes, it would seem there is little difference in the paths, so there is probably no point doing that. I still think it’s something in CB’s auto-complete that’s not quite up to the task, or needs some tweaking.

For CB, you get the platformio.cbp file, and possibly the platformio.layout, but the latter is unimportant.
https://termbin.com/1g24x

For VSCode, you get .vscode/c_cpp_properties.json as the important one.
https://termbin.com/nsxy

@pfeerick, the vscode runs on linux too. I had in on fedora some time ago. just fyi.

1 Like

I put together a simple C++ project in CB (Dropbox - Test_CB.tar.gz - Simplify your life) .
Observations:
a. CB config only tracks explicitly added files. Regardless of what those files are - header or cpp.
https://termbin.com/nlqe

<Unit filename="lib/lib_1/lib_1.cpp" />
		<Unit filename="lib/lib_1/lib_1.h" />
		<Unit filename="lib/test.cpp" />
		<Unit filename="lib/test.h" />
		<Unit filename="src/main.cpp" />

All the above were explicitly added to the project.

at the same time “termcolor” library was only added thru the include:

#include <iostream>
#include "../lib/lib_1/lib_1.h"
#include "../lib/test.h"
#include "../lib/termcolor/include/termcolor/termcolor.hpp"

if we look at the PIO’s cbp - they add all libraries explicitly:

<Add directory="E:/Projects/PlatformIO/forumPlayground/codeblocks/include"/>
			<Add directory="E:/Projects/PlatformIO/forumPlayground/codeblocks/src"/>
			<Add directory="E:/Projects/PlatformIO/forumPlayground/codeblocks/.pio/libdeps/uno/EasyButton/src"/>
			<Add directory="E:/Projects/PlatformIO/forumPlayground/codeblocks/.pio/libdeps/uno/ArduinoJson/src"/>
			<Add directory="C:/Users/Peter/.platformio/packages/framework-arduino-avr/cores/arduino"/>
			<Add directory="C:/Users/Peter/.platformio/packages/framework-arduino-avr/variants/standard"/>
			<Add directory="C:/Users/Peter/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src"/>

so unless “add directory” == “include”, then CB’s parser will be pretty much messed up when i add

#include "ArduinoJson.h"

vs

#include "../lib/ArduinoJson/ArduinoJson.h"

Yeah, I run VSCode on both Windows and Linux - it’s just that I had inited the CB project on Windows, and was in Linux at the time I posted, so couldn’t give comparable files from the same OS :wink:

So what’s the verdict (I haven’t had coffee yet)? If I understand what you are saying right, CodeBlocks wants paths relative to the project root rather than absolute paths?

i.e. since the project was located in

E:/Projects/PlatformIO/forumPlayground/codeblocks/

instead of

<Add directory="E:/Projects/PlatformIO/forumPlayground/codeblocks/.pio/libdeps/uno/ArduinoJson/src"/>

CB wants

<Add directory=".pio/libdeps/uno/ArduinoJson/src"/>

for it’s autocomplete to work?

well, not exactly :slight_smile:
for CB auto-completion to work in “#include” you have to specify the path to corresponding .H file.
“add directory” does that in cbp file.
Should it be an absolute or relative path? It would, probably, only matter, if share the project between 2 different CB installations.

PIO replaces the flexibility of CB project configuration with autogenerated cbp. It was assumed that all libraries should have an identical structure:
lib_1
|- src
| | - lib.cpp
| | - lib.h
In case of termcolor this assumption is incorrect.
for termcolor:

termcolor/include/termcolor/termcolor.hpp

ArduinoJson:
ArduinoJson
| ArduinoJson.h
| ./src
| | ArduinoJson.h
| | ArduinoJson.hpp
| | ./ArduinoJson
| | | <tons of hpp files been #included in the upper level hpp>

why CB is suggesting ArduinJson/ArduinoJson.h i’m still not sure.

Ah, ok, gotcha… I think. :open_mouth: The PlatformIO init’ed cbp only points to the library folder, not caring if the .h is in an \src, \include\ subfolder, etc.

Hm, The other possible weirdity with the ArduionJson library is there are two ArduinoJson’s … one in the root, and the other in the ‘/src’ subfolder…