本帖最后由 xbin 于 2026-5-29 16:01 编辑
keil 在 `Options for Target -> C/C++ -> Define` 处定义宏 CONFIG_A, CONFIG_FILE=\"config.h\", CONFIG_B
其中我发现 CONFIG_B 并没有被定义,好像是没有被解析出来。
如果 CONFIG_B 定义在 CONFIG_FILE=\"config.h\" 前面就没有问题
我看 mbedtls 中就是这种写法
[C] 纯文本查看 复制代码
// Middlewares/Third_Party/mbedTLS/include/mbedtls/build_info.h
/* X.509, TLS and non-PSA crypto configuration */
#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/mbedtls_config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
下面是测试用例:
[C] 纯文本查看 复制代码
#if defined(CONFIG_A)
int a[-1];
#endif
#include CONFIG_FILE
#if defined(CONFIG_B)
int b[-1];
#endif
int main() {
return 0;
}
/*
uVision V5.26.0.0
1. CONFIG_A, CONFIG_B, CONFIG_FILE=\"config.h\"
```txt
Build target 'A_B_FILE'
compiling main.c...
main.c(2): error: #94: the size of an array must be greater than zero
int a[-1];
main.c(8): error: #94: the size of an array must be greater than zero
int b[-1];
main.c: 0 warnings, 2 errors
".\Objects\keil_test.axf" - 2 Error(s), 0 Warning(s).
```
2. CONFIG_A, CONFIG_FILE=\"config.h\", CONFIG_B
```txt
Build target 'A_FILE_B'
compiling main.c...
main.c(2): error: #94: the size of an array must be greater than zero
int a[-1];
main.c: 0 warnings, 1 error
".\Objects\keil_test.axf" - 1 Error(s), 0 Warning(s).
```
*/
|