如何获取 Visual Studio 代码以包含带尖括号 <> 的非标准库?
How do I get Visual Studio Code to include non-standard libraries with angle brackets <>?
我正在尝试 运行 使用 ArduinoJson library with the VSC extension Code Runner 的程序,但我无法编译它。
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 命令和一些使用尖括号的命令:
#include "src/ArduinoJson.h"
//...
#include <ArduinoJson/Array/ArrayFunctions.hpp>
看来只有带尖括号的 include 语句有问题。我已经尝试在 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"]
有人知道我可能做错了什么吗?
我的文件夹结构是
project/
--src/
----localtest.cpp
--External_Libraries/
----ArduinoJson/
我认为您应该将最后一个 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"]
我找到了一个解决方法:我安装了 Compile Run 扩展而不是代码 运行ner,并将其配置为使用 g++ 而不是 gcc,编译器参数为“-I C:/.../project/External_Libraries/ArduinoJson/src" -> 这有效!
在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",
Code 运行ner 扩展似乎使用了不同的编译器和路径,我无法正确更新。编译 运行 允许为此扩展设置特定的编译器和路径,因此在我看来这更容易处理。
我仍然非常想知道如何正确更新编译器并包含代码 运行ner 的路径。
我正在尝试 运行 使用 ArduinoJson library with the VSC extension Code Runner 的程序,但我无法编译它。
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 命令和一些使用尖括号的命令:
#include "src/ArduinoJson.h"
//...
#include <ArduinoJson/Array/ArrayFunctions.hpp>
看来只有带尖括号的 include 语句有问题。我已经尝试在 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"]
有人知道我可能做错了什么吗?
我的文件夹结构是
project/
--src/
----localtest.cpp
--External_Libraries/
----ArduinoJson/
我认为您应该将最后一个 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"]
我找到了一个解决方法:我安装了 Compile Run 扩展而不是代码 运行ner,并将其配置为使用 g++ 而不是 gcc,编译器参数为“-I C:/.../project/External_Libraries/ArduinoJson/src" -> 这有效!
在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",
Code 运行ner 扩展似乎使用了不同的编译器和路径,我无法正确更新。编译 运行 允许为此扩展设置特定的编译器和路径,因此在我看来这更容易处理。
我仍然非常想知道如何正确更新编译器并包含代码 运行ner 的路径。