gpt4 book ai didi

使用 Ceedling 定义编译器标志

转载 作者:行者123 更新时间:2023-12-02 18:30:40 26 4
gpt4 key购买 nike

我有一个嵌入式系统项目,正在使用 Ceedling(=Unity 和 Cmock)进行测试。

在一个测试用例中,被测代码就是这么简单:

uint32_t zero = eeprom_read_dword((uint32_t*)&non_volatile_zero);
sprintf(output, "%lu", zero);

由于嵌入式系统是8位架构,因此在sprintf中必须使用%lu来格式化32位unsigned int进行打印。但是,桌面环境(GCC)用于测试构建和测试运行(并且不能选择使用嵌入式构建进行测试)。这会导致下一个警告:

warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘uint32_t’ {aka ‘unsigned int’} [-Wformat=]
62 sprintf(output, "%lu", zero);
~~^ ~~~~
| |
| uint32_t {aka unsigned int}
long unsigned int
%u

警告本身在桌面环境中是正确的,但从嵌入式系统的角度来看是误报。

我的问题是如何为测试build设置 -Wno-format 编译器标志,因为我根本没有在 project.yml 中定义工具部分,因为使用了默认的 GCC?或者也许有一种方法可以告诉 ceedling 目标系统正在使用 8 位架构?

最佳答案

如果有人碰巧搜索原始问题的答案,这里有一个解决方案,如何为指定的源文件添加编译器标志,而无需在 project.yml 中定义整个工具部分:

# Adds -Wno-format for sourcefile.c
:flags:
:test:
:compile:
:sourcefile: # use :*: for all sources.
- -Wno-format

关于使用 Ceedling 定义编译器标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69460722/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com