我刚刚安装了最新版本的 VScode,以及 Arduino 扩展和最新的 ESP-IDF,我正在尝试对 adafruit esp32 羽毛进行编程。
使用我在 Arduino IDE 版本 1.8.15 中编写的代码并在测试版 Arduino-DE 2.0.9 中进行测试时,我没有出现任何错误。
初始样本为:
#include <array>
//#include <utility/imumaths.h>
//#include <driver/adc.h>
#include <MPU9250.h>
#include <Madgwick.h>
#include <TaskScheduler.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <driver/adc.h>
//#define betaDef = 10f;
Adafruit_BNO055 bno = Adafruit_BNO055(-1, 0x28);
std::array<std::array<float, 3> , 2> vals = {0};
void taskPrint();
//Tasks
Task t1(1, TASK_FOREVER, &taskPrint);
Scheduler runner;
void taskPrint() {
Serial.print(vals[0][0]);
Serial.print(',');
Serial.print(vals[0][1]);
Serial.print(',');
Serial.print(vals[0][2]);
Serial.print(',');
Serial.print(vals[1][0]);
Serial.print(',');
Serial.print(vals[1][1]);
Serial.print(',');
Serial.println(vals[1][2]);
};
第 13 行的第一个错误 (namespace "std" has no member "array"
)。
在 VScode 中使用相同的代码时,Vscode 会验证、抱怨,但无论如何都会编译和上传(代码在 esp32 上继续正常工作)。带有不断的波浪线标记和错误。
我已经检查了 c_cpp_properties,其中似乎 esp-idf 正在使用版本 c++11。
"version": 4,
"configurations": [
{
"name": "Arduino",
"compilerPath": "C:\\Users\\computer\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\xtensa-esp32-elf-gcc\\1.22.0-97-gc752ad5-5.2.0\\bin\\xtensa-esp32-elf-g++",
"compilerArgs": [
"-std=gnu++11",
"-Wpointer-arith",
"-fexceptions",
"-fstack-protector",
"-ffunction-sections",
"-fdata-sections",
"-fstrict-volatile-bitfields",
"-mlongcalls",
"-nostdlib",
"-w",
"-Wno-error=maybe-uninitialized",
"-Wno-error=unused-function",
"-Wno-error=unused-but-set-variable",
"-Wno-error=unused-variable",
"-Wno-error=deprecated-declarations",
"-Wno-unused-parameter",
"-Wno-unused-but-set-parameter",
"-Wno-missing-field-initializers",
"-Wno-sign-compare",
"-fno-rtti"
],
"intelliSenseMode": "gcc-x64",
"includePath": [
//a whole tonne of paths
]
"forcedInclude":["C:\\Users\\computer\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.6\\cores\\esp32\\Arduino.h"
],
"cStandard": "c11",
"cppStandard": "c++11",
"defines": [ tonnes of defines
]
}
]
}
检查 std::array 的 cpp ref 这应该在 cp++11 中支持
修改这个文件只会导致 Vscode 用原来的设置覆盖它,因为这个错误,我只能假设我得到的其他错误是相关的(似乎我的数组都有各种问题。
namespace "std" has no member "array"C/C++(135)
identifier "vals" is undefinedC/C++(20)
qualified name is not allowedC/C++(283)
explicit type is missing ('int' assumed)C/C++(260)
mag_offsets" is not a nonstatic data member or base class of class "euler"C/C++(292)
虽然我的编码很差,但我很确定这个问题与程序或编译器设置有关,而不是我缺乏能力。
如何解决这个命名空间问题?我想使用 Vscode 对我的嵌入式项目进行编程……但目前,我从 Intellisense 那里得到了看似虚假的报告。
答案 0 :(得分:0)
在没有所有文件的情况下重现您的错误有点困难,但我建议使用 xtensa-esp32-elf-gcc 而不是 xtensa-esp32-elf-g++ > 在 compilerPath 中,因为 Microsoft C/C++ 扩展似乎可以与 gcc 一起使用。
另一个问题可能是 includePaths 或定义中的冲突引用。如果第一种方法不起作用,我建议删除它们。