我希望有人能解释为什么这段代码不能在 Arduino IDE 中编译(使用 1.0.5)。以下代码仅在 DEBUG=1 时编译,但在设置为 0 时编译。
我希望实现的只是一种在我交换 LED 驱动器时使用相同代码的简单方法,并在重新编译和上传之前翻转 DEBUG 位。
注意:本示例是IDE中要编译的全部代码(不需要其他代码)。
问题代码:
#define DEBUG 0 //DEBUG=1 works, DEBUG=0 causes compiler error
#if DEBUG == 1
int x = 123;
//Adafruit_8x8matrix matrix = Adafruit_8x8matrix();
#else
int x = 567;
//Adafruit_BicolorMatrix matrix = Adafruit_BicolorMatrix();
#endif
void setup() { }
void loop() { }
Run Code Online (Sandbox Code Playgroud)
错误:
core.a(main.cpp.o): In function `main':
C:\arduino\hardware\arduino\cores\arduino/main.cpp:11: undefined reference to `setup'
C:\arduino\hardware\arduino\cores\arduino/main.cpp:14: undefined reference to `loop'
Run Code Online (Sandbox Code Playgroud)