PlatformIO Community

ArduinoJson library errors on compile

I have added ArduinoJson to the lib_deps section of my platformio.ini file, however when I compile, I get the following error:

from .pio\libdeps\nanoatmega328\ArduinoJson_ID64\src/ArduinoJson.h:9,
from src\main.cpp:109:
.pio\libdeps\nanoatmega328\ArduinoJson_ID64\src/ArduinoJson/Array/…/Variant/…/Misc/…/Strings/…/Memory/…/Variant/…/Polyfills/type_traits.hpp:7:39: fatal error: type_traits/conditional.hpp: No such file or directory
compilation terminated.
*** [.pio\build\nanoatmega328\src\main.cpp.o] Error 1

Any ideas?

This minimal example compiles:

platformio.ini

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
lib_deps =
    ArduinoJson

main.cpp

#include <Arduino.h>
#include "ArduinoJson.h"

void setup() {
}

void loop() {
}

Can you provide more information so your situation can be reproduced:

  • platformio.ini
  • minimal main.cpp
  • Operation system, version etc.
1 Like

Thank you. I have copied your example into a new project, and it does compile.

However when I update my new empty project with more libraries, see below, it does not compile. Following your template:

platformio.ini

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
lib_deps =
ArduinoJson
Ethernet
PubSubClient
LiquidCrystal

main.cpp

#include <Arduino.h>
#include “ArduinoJson.h”
#include “LiquidCrystal.h”
#include “PubSubClient.h”
#include “Ethernet.h”

void setup() {
}

void loop() {
}

My setup: PlatformIO in Visual Studio Code, running on Windows 10.

By the way, I have tried uninstalling all libraries from PlatformIO home under the project, then reinstalling them. I get the same problem.

Here is the compile error in full. This is the compile error for the minimal example in this post, different to the error I posted before, because I removed all the code in main.cpp.

Processing nanoatmega328 (platform: atmelavr; board: nanoatmega328; framework: arduino)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328.html
PLATFORM: Atmel AVR 1.15.0 > Arduino Nano ATmega328
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
PACKAGES: toolchain-atmelavr 1.50400.190710 (5.4.0), framework-arduinoavr 4.1.1
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 9 compatible libraries
Scanning dependencies…
Dependency Graph
|-- 6.11.3
|-- 2.0.0
| |-- 1.0
|-- 2.7
|-- 1.5.0
Compiling .pio\build\nanoatmega328\src\main.cpp.o
Archiving .pio\build\nanoatmega328\libd29\libArduinoJson_ID64.a
Compiling .pio\build\nanoatmega328\lib4be\SPI\SPI.cpp.o
Compiling .pio\build\nanoatmega328\lib16b\Ethernet_ID872\Dhcp.cpp.o
Compiling .pio\build\nanoatmega328\lib16b\Ethernet_ID872\Dns.cpp.o
Compiling .pio\build\nanoatmega328\lib16b\Ethernet_ID872\Ethernet.cpp.o
Compiling .pio\build\nanoatmega328\lib16b\Ethernet_ID872\EthernetClient.cpp.o
Compiling .pio\build\nanoatmega328\lib16b\Ethernet_ID872\EthernetServer.cpp.o
Compiling .pio\build\nanoatmega328\lib16b\Ethernet_ID872\EthernetUdp.cpp.o
Archiving .pio\build\nanoatmega328\lib4be\libSPI.a
Compiling .pio\build\nanoatmega328\lib16b\Ethernet_ID872\socket.cpp.o
Compiling .pio\build\nanoatmega328\lib16b\Ethernet_ID872\utility\w5100.cpp.o
Compiling .pio\build\nanoatmega328\lib6a0\PubSubClient_ID89\PubSubClient.cpp.o
Compiling .pio\build\nanoatmega328\lib035\LiquidCrystal_ID136\FastIO.cpp.o
Compiling .pio\build\nanoatmega328\lib035\LiquidCrystal_ID136\I2CIO.cpp.o
Compiling .pio\build\nanoatmega328\lib035\LiquidCrystal_ID136\LCD.cpp.o
Compiling .pio\build\nanoatmega328\lib035\LiquidCrystal_ID136\LiquidCrystal.cpp.o
Compiling .pio\build\nanoatmega328\lib035\LiquidCrystal_ID136\LiquidCrystal_I2C.cpp.o
.pio\libdeps\nanoatmega328\PubSubClient_ID89\src\PubSubClient.cpp: In member function ‘boolean PubSubClient::beginPublish(const char*, unsigned int, boolean)’:
.pio\libdeps\nanoatmega328\PubSubClient_ID89\src\PubSubClient.cpp:456:18: warning: unused variable ‘i’ [-Wunused-variable]
uint16_t i;
^
.pio\libdeps\nanoatmega328\LiquidCrystal_ID136\I2CIO.cpp:54:21: fatal error: Wire.h: No such file or directory
Compiling .pio\build\nanoatmega328\lib035\LiquidCrystal_ID136\LiquidCrystal_I2C_ByVac.cpp.o



compilation terminated.
*** [.pio\build\nanoatmega328\lib035\LiquidCrystal_ID136\I2CIO.cpp.o] Error 1
In file included from .pio\libdeps\nanoatmega328\LiquidCrystal_ID136\LiquidCrystal_I2C_ByVac.cpp:46:0:
.pio\libdeps\nanoatmega328\LiquidCrystal_ID136\LiquidCrystal_I2C_ByVac.h:56:21: fatal error: Wire.h: No such file or directory



compilation terminated.
*** [.pio\build\nanoatmega328\lib035\LiquidCrystal_ID136\LiquidCrystal_I2C_ByVac.cpp.o] Error 1
============================================================================ [ERROR] Took 11.81 seconds ============================================================================
The terminal process terminated with exit code: 1

Ok so I have changed the minimal example to add Wire.h and this example works.

BUT - I’m still getting the error posted in my first post, with the my sketch code inserted.

(this works ok:)
platformio.ini

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
lib_deps =
ArduinoJson
Ethernet
PubSubClient
LiquidCrystal
Wire

main.cpp

#include <Arduino.h>
#include “Wire.h”
#include “ArduinoJson.h”
#include “LiquidCrystal.h”
#include “PubSubClient.h”
#include “Ethernet.h”

void setup() {
}

void loop() {
}

Should I post my whole sketch here?

Your code compiles in my machine.

Could the path be too long for Windows?

.pio\libdeps\nanoatmega328\ArduinoJson_ID64\src/ArduinoJson/Array/…/Variant/…/Misc/…/Strings/…/Memory/…/Variant/…/Polyfills/type_traits.hpp

I can’t really tell. I’m not using Windows.

The Wire issue is also very interesting. It’s sufficient to add it as an include to main.cpp. Then it compiles with the following dependency graph:

Dependency Graph
|-- <ArduinoJson> 6.11.3
|-- <Ethernet> 2.0.0
|   |-- <SPI> 1.0
|-- <PubSubClient> 2.7
|-- <LiquidCrystal> 1.5.0
|   |-- <Wire> 1.0
|-- <Wire> 1.0

Without including it (neither in main.cpp nor as an explicit dependency in platformio.ini), it fails to compile (.pio\libdeps\nanoatmega328\LiquidCrystal_ID136\I2CIO.cpp:54:21: fatal error: Wire.h: No such file or directory) because the dependency graph is incorrect:

Dependency Graph
|-- <ArduinoJson> 6.11.3
|-- <Ethernet> 2.0.0
|   |-- <SPI> 1.0
|-- <PubSubClient> 2.7
|-- <LiquidCrystal> 1.5.0

In this case, it fails to determine that LiquidCrystal depends on Wire.

Can anybody with a better understanding of the library manager comment on this? Is this the expected behavior?

I can reproduce your bug. It’s indeed related to the path length.

My first attempt on Windows was ok: it compiled. Then I moved the project to a location with a longer path and now I get the same error as well.

So the solution is: Move your project to a location with a short path.

And possibly open an issue for the ArduinoJson library to have them change their includes such that the path is shorter. It should be too difficult to prevent paths like:

ArduinoJson/Array/…/Variant/…/Misc/…/Strings/…/Memory/…/Variant/…/Polyfills/type_traits.hpp
1 Like

As for the Wire dependency, you either need to explicitly include it in main.cpp or switch the LDF mode to chain+, as Wire.h is hidden under a preprocessor condition.

2 Likes

lib_ldf_mode = deep actually … I thought chain+ would work also, but it seems I2CIO.h isn’t in the direct include chain(?), hence failed miserably. I was surprised though that it didn’t need deep+ because of the preprocessor macro …

However, one will notice if they look at the examples for that particular library that it shows …

#include <Wire.h>
#include <LiquidCrystal.h>

… on most (if not all) the provided examples so it looks like because of how the library is written it’s needed all the time.

1 Like