0

I am trying to run a program using the ArduinoJson library with the VSC extension Code Runner but I cannot compile it.

There are no markup errors or warnings in VSC but when I try to run this snippet:

#include "../External_Libraries/ArduinoJson/ArduinoJson.h"
#include <iostream>
int main(){
    std::cout << "Done.\n";
    return 0;}

I get the error output below:

In file included from ../External_Libraries/ArduinoJson/src/ArduinoJson.hpp:17,\
                 from ../External_Libraries/ArduinoJson/src/ArduinoJson.h:9,\
                 from ../External_Libraries/ArduinoJson/ArduinoJson.h:5,\
                 from localtest.cpp:17:\ ../External_Libraries/ArduinoJson/src/ArduinoJson/Array/ArrayRef.hpp:7:10: fatal error:\ ArduinoJson/Array/ArrayFunctions.hpp: No such file or directory\
#include <ArduinoJson/Array/ArrayFunctions.hpp>\
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\ compilation terminated.

Inside the ArduinoJson library, there are some include commands using double quotes and some using angle brackets:

#include "src/ArduinoJson.h"
//...   
#include <ArduinoJson/Array/ArrayFunctions.hpp>

It appears that only the include statements with angle brackets are a problem. I have tried updating my include paths in settings.json as well as in c_cpp_properties.json to cover this, but it has not worked:

In settings.json:

"C_Cpp.default.includePath": [
    "C:\\...\\project",
    "C:\\...\\project\\External_Libraries\\ArduinoJson\\src",
    "C:\\...\\project\\External_Libraries\\ArduinoJson\\src\\ArduinoJson\\Array"],
"C_Cpp.default.compilerPath": "C:\\MinGW\\bin\\gcc.exe"

In c_cpp_properties.json:

"name": "Win32",
"includePath":[
    "${default}",
    "C:/.../project",
    "C:/.../project/External_Libraries/ArduinoJson/src/ArduinoJson/Array"],
"defines":[
    "_DEBUG",
    "UNICODE",
    "_UNICODE"],
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x86",
"compilerPath": "C:/MinGW/bin/gcc.exe",
"compilerArgs": ["-I C:\\...\\project\\External_Libraries"]

Does anyone have any ideas what I might be doing wrong?

My folder structure is

project/
--src/
----localtest.cpp
--External_Libraries/
----ArduinoJson/

2 Answers2

1

I think you should change last includePath to "C:/.../project/External_Libraries/ArduinoJson/src". That is because actual include already has it as relative path #include <ArduinoJson/Array/ArrayFunctions.hpp>

      "name": "Win32",
  "includePath":[
      "${default}",
      "C:/Users/pohl/Documents/Git/IDEAL_AgentsOnHardware",
      "C:/.../project/External_Libraries/ArduinoJson/src"],
  "defines":[
      "_DEBUG",
      "UNICODE",
      "_UNICODE"],
  "cStandard": "gnu17",
  "cppStandard": "gnu++14",
  "intelliSenseMode": "windows-gcc-x86",
  "compilerPath": "C:/MinGW/bin/gcc.exe",
  "compilerArgs": ["-I C:\\...\\project\\External_Libraries"]
Nimantha
  • 6,405
  • 6
  • 28
  • 69
  • Thanks for the reply. You have a good point but unfortunately it didn't work. I get the same error message. Are there maybe different include paths for different things in VSC? Is there a specific include path for the Code Runner extension for example? – systemoutprintlnargs Jun 29 '21 at 15:36
  • 1
    have you already tried to do same path change for `C_Cpp.default.includePath`? If not, could you try? –  Jun 29 '21 at 15:43
  • I have tried that, too - but to no avail. I still get the same error message. When I compile this on a Linux machine however, I have a symlink named "ArduinoJson" to the ArduinoJson/src directory in the same directory as localtest.cpp and just use "-I ArduinoJson" to include that - and this works! Unfortunately though, I cannot use symlinks on my Windows machine. – systemoutprintlnargs Jun 30 '21 at 06:17
  • 1
    I looked at https://github.com/bblanchon/ArduinoJson. The file ArduinoJson/src/ArduinoJson.hpp does not have that include. Perhaps you have changed source? Could you check. Also, try replacing \\ with /. Lastly look at this: https://stackoverflow.com/questions/37522462/visual-studio-code-includepath –  Jun 30 '21 at 06:36
  • The problem arises at line 17 of ArduinoJson.hpp, which includes "ArduinoJson/Array/ArrayRef.hpp" and in ArrayRef.hpp at line 7 we find #include which causes the problem. I replaced all \\ but still it doesn't work. Your linked question gave me an idea though. Instead of "Code Runner" I installed the "Compile Run" extension and configured it to use g++ instead of gcc with the compiler argument "-I C:/.../project/External_Libraries/ArduinoJson/src" -> and this works! The Code Runner extension seems to be using different compiler and paths, I guess. – systemoutprintlnargs Jun 30 '21 at 07:03
0

I found a workaround: Instead of Code Runner I installed the Compile Run extension and configured it to use g++ instead of gcc with the compiler argument "-I C:/.../project/External_Libraries/ArduinoJson/src" -> and this works!

In settings.json:

"c-cpp-compile-run.cpp-compiler": "C:/MinGW/bin/g++.exe",
"c-cpp-compile-run.cpp-flags": "-Wall -Wextra -Wa,-mbig-obj -I C:/.../project/External_Libraries/ArduinoJson/src",

The Code Runner extension seems to be using a different compiler and paths which I have not been able to properly update. Compile Run allows to set specific compiler and paths just for this extension, so that's easier to handle in my opinion.

I would still very much like to know how I can properly update the compiler and include paths for Code Runner.