在代码中访问 Makefile 变量? [英] Accessing Makefile variables in code?

查看:25
本文介绍了在代码中访问 Makefile 变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新进度

抱歉,我忘记将此问题指定为 Arduino 问题.我只是假设这是一个预处理器问题,与正在执行的平台无关.

我正在使用 Arduino-Make 并尝试传入 USERNAME 和 PASSWORD

BOARD_TAG = mega2560CPPFLAGS = -DUSERNAME="$(USERNAME)" -DPASSWORD="$(PASSWORD)"包括 $(ARDMK_DIR)/Arduino.mk

命令行:

设置 USERNAME="HELLO" PASSWORD="WORLD"

代码:

void setup() {Serial.begin(9600);字符串 auth_raw2(用户名:密码);Serial.println(auth_raw2);}无效循环(){}

我收到此错误:

macro.ino:10:29: 错误:在嵌套名称说明符中找到:",预期为::"macro.ino:10:20: 错误:HELLO"尚未声明

解决方案

根据 Arduino 网站上的文献:>

在构造函数中连接 "会产生不可预测的结果,因为在您开始连接不同的数据类型.为获得最佳结果,请在连接字符串之前对其进行初始化."

<小时>

就您传递给 makefile 的变量而言,语法是正确的,用于定义这些变量的命令行 -D 也是有效的.但是,正如文档所指出的,在传递给构造函数时应该避免混合整数和字符串,尽管首先构造字符串然后连接值是完全有效的.

UPDATED PROGRESS

I am sorry I forgot to specify this question as an Arduino question. I just assumed that it's a preprocessor problem which is kind of independent of what platform this is being executed on.

I am using Arduino-Make and I am trying to pass in USERNAME and PASSWORD

BOARD_TAG    = mega2560
CPPFLAGS     = -DUSERNAME="$(USERNAME)" -DPASSWORD="$(PASSWORD)"
include $(ARDMK_DIR)/Arduino.mk

Command line:

make USERNAME="HELLO" PASSWORD="WORLD"

Code:

void setup() {
  Serial.begin(9600);

  String auth_raw2(USERNAME : PASSWORD);
  Serial.println(auth_raw2);
}


void loop() {}

I am getting this error:

macro.ino:10:29: error: found ‘:’ in nested-name-specifier, expected ‘::’
macro.ino:10:20: error: ‘HELLO’ has not been declared

解决方案

According to the literature at Arduino's Site:

Concatenating in a constructor "gives unpredictable results because 'auth_raw' never got an initial value before you started concatenating different data types. For best results, initialize your Strings before you concatenate them."


As far as the variables you are passing to your makefile are concerned, the syntax is correct, and the commandline -D to define those variables is as well valid. However, as the documentation points out, you should avoid mixing integers and strings when passing to a constructor, though it would be perfectly valid to construct the String first, and then concatenate the values.

这篇关于在代码中访问 Makefile 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆