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/
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.