问题描述
我有以下 Makefile(如果你问我为什么包含 \" 你可以参考我的 上一个问题)
I have the following Makefile (If you are asking me why there's \" included you can refer to my previous question)
BOARD_TAG = mega2560
CPPFLAGS = -DUSERNAME=\"$(USERNAME)\" -DPASSWORD=\"$(PASSWORD)\"
include $(ARDMK_DIR)/Arduino.mk
和代码:
void setup() {
Serial.begin(9600);
String auth_raw2(USERNAME ":" PASSWORD);
Serial.println(auth_raw2);
}
void loop() {}
当我用 make USERNAME=hello PASSWORD=world
编译它时,一切正常,我看到 'hello:world' 被打印出来.
when I compile this with make USERNAME=hello PASSWORD=world
, everything works and I see 'hello:world' being printed out.
但是,如果我将 USERNAME 替换为 SERIAL,将 PASSWORD 替换为 TOKEN:
However, if I substitute USERNAME to SERIAL and PASSWORD to TOKEN:
BOARD_TAG = mega2560
CPPFLAGS = -DSERIAL=\"$(SERIAL)\" -DTOKEN=\"$(TOKEN)\"
include $(ARDMK_DIR)/Arduino.mk
和
void setup() {
Serial.begin(9600);
String auth_raw2(SERIAL ":" TOKEN);
Serial.println(auth_raw2);
}
void loop() {}
我收到错误,macro.ino:5:27: error: expected ‘)’ before string constant
请注意,$USERNAME 在我的 linux 机器上定义为 disappearedng
而 $PASSWORD、$SERIAL 和 $TOKEN 未定义.
Note that $USERNAME is defined on my linux box as disappearedng
while $PASSWORD, $SERIAL, and $TOKEN are undefined.
为什么这适用于 USERNAME:PASSWORD 而不适用于 SERIAL:TOKEN?
推荐答案
所以看起来 Arduino 覆盖了 $SERIAL 参数.
So it seems like Arduino overrides the $SERIAL parameter.
将 SERIAL 切换到 DSERIAL 使编译正常
Switching SERIAL to DSERIAL makes compiling ok
这篇关于使用 USERNAME:PASSWORD 但不适用于 SERIAL:TOKEN 的字符串化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!