Stringification working with USERNAME:PASSWORD but

2019-09-09 11:03发布

问题:

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

and code:

void setup() {
  Serial.begin(9600);
  String auth_raw2(USERNAME ":" PASSWORD);
  Serial.println(auth_raw2);
}
void loop() {}

when I compile this with make USERNAME=hello PASSWORD=world, everything works and I see 'hello:world' being printed out.

However, if I substitute USERNAME to SERIAL and PASSWORD to TOKEN:

BOARD_TAG    = mega2560
CPPFLAGS     = -DSERIAL=\"$(SERIAL)\" -DTOKEN=\"$(TOKEN)\"
include $(ARDMK_DIR)/Arduino.mk

and

void setup() {
  Serial.begin(9600);
  String auth_raw2(SERIAL ":" TOKEN);
  Serial.println(auth_raw2);
}
void loop() {}

I am getting the error, macro.ino:5:27: error: expected ‘)’ before string constant

Note that $USERNAME is defined on my linux box as disappearedng while $PASSWORD, $SERIAL, and $TOKEN are undefined.

WHY does this work for USERNAME:PASSWORD but not for SERIAL:TOKEN?

回答1:

So it seems like Arduino overrides the $SERIAL parameter.

Switching SERIAL to DSERIAL makes compiling ok