如何使用Zephyr检查Kconfig字符串是否为空?

问题描述

给出此Kconfig:

config MY_STR
    string "A string"

伪指令#if defined(CONFIG_MY_STR)对于默认的空字符串将评估为true。

如何在编译时检查 CONFIG_MY_STR 是否为空字符串?像下面这样使用第二个布尔值(例如 CONFIG_USE_MY_STR )是更好的做法吗?

config MY_STR
    string "A string"
    depends on USE_MY_STR

config USE_MY_STR
    bool "Enable MY_STR"

解决方法

由于string symbols implicitly default to the empty stringBUILD_ASSERT()可用于执行编译时检查:

BUILD_ASSERT(1 != sizeof(CONFIG_SOMEPROPERTY),"SOMEPROPERTY required");

并在构建过程中将其传递给

west build -- -DCONFIG_SOMEPROPERTY=\"1.0\" [other arguments]

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...