0

我正在尝试使用带有 VSC 扩展Code Runner的ArduinoJson库运行程序,但我无法编译它。

VSC 中没有标记错误或警告,但是当我尝试运行此代码段时:

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

我得到下面的错误输出:

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.

在 ArduinoJson 库中,有一些使用双引号的包含命令和一些使用尖括号的命令:

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

似乎只有带有尖括号的包含语句是一个问题。我已经尝试在 settings.json 以及 c_cpp_properties.json 中更新我的包含路径以涵盖这一点,但它没有奏效:

在 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"

在 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"]

有谁知道我可能做错了什么?

我的文件夹结构是

项目/
--src/
----localtest.cpp --External_Libraries
/
----ArduinoJson/

4

2 回答 2

1

我认为您应该最后更改includePath为“C:/.../project/External_Libraries/ArduinoJson/src”。那是因为实际包含已经将它作为相对路径#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"]
于 2021-06-29T13:57:21.013 回答
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.

于 2021-06-30T07:08:54.387 回答