Arduino IDE - 将库代码复制到草图文件夹时,奇怪的 #endif 没有 #if

问题描述 投票:0回答:1

我正在 Wemos D1 R1 板上使用 Espalexa 库实现 IoT 设备,我想对库代码进行一些修改,因此我将库文件从 Arduino 库文件夹复制到我的 sketch 目录,以便在复制。我更改了库头文件名以避免与库冲突(从 Espalexa.h 到 Espalexamod.h),但现在它无法编译,给我这个意外的错误。

首先,通过使用包含的库进行编译一切正常,而在尝试编译以下草图之后:

#include "Espalexamod.h"

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

它给了我以下意外错误:

C:\path\to\sketch\Espalexamod.h:610:2: error: #endif without #if
  610 | #endif
      |  ^~~~~
exit status 1

Compilation error: #endif without #if

具体来说,这是代码中的最后一个#endif(关闭守卫定义的那个),我还尝试将守卫定义更改为另一个名称,并检查代码上的所有定义是否都已关闭(但这很明显,因为通过使用图书馆正常,一切正常)。

作为最后一次尝试,我在文件上评论了#endif,编译后它给出了另一个意外错误

C:\bath\to\sketch\Espalexamod.h:1:1: error: '<?>' does not name a type
    1 | <?>#ifndef Espalexa_h
      |  

exit status 1

Compilation error: stray '#' in program

其中实际上是一个菱形问号符号,所以看来这次它根据需要正确识别了最后的#endif(因为它是需要的!)

在此之后我真的要疯了,我还尝试了 Ide 1.x 和 2.x,我尝试删除构建缓存并从头开始创建一个新的草图,似乎没有任何效果。 有什么建议吗?预先感谢。

arduino compilation arduino-ide
1个回答
0
投票

不属于。该错误导致

#ifndef Espalexa_h
不可见。因此,当您到达
#endif
时,就没有之前的 if 因为
#ifndef
没有被读取。

© www.soinside.com 2019 - 2024. All rights reserved.