c - 如何让 GCC (Xtensa 5.1) 识别定义

标签 c gcc conditional-compilation

例如,我有这个 c 源文件(摘录)

#ifdef USE_OUPUTS
#pragma message "Outputs"
static const uint8 outputMap[MAX_OUTPUT] = { RELAY_1, RELAY_2, RELAY_3, RELAY_4, LED };
static bool currentOutputs[MAX_OUTPUT];
static bool outputOverrides[MAX_OUTPUT];

uint8 ICACHE_FLASH_ATTR getOutput(uint8 idx) {
    return currentOutputs[idx];
}

void ICACHE_FLASH_ATTR setOutput(int id, int value) {
.
.
}

void ICACHE_FLASH_ATTR initOutput(void) {
.
.
}
#else
#pragma message "No Outputs"

#endif

我使用以下命令调用编译器(通过 makefile):

c:/Espressif/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -v -DUSE_OUTPUTS=1 -U SLEEP_MODE -Iuser -Icommon/mqtt -Icommon/temperature -Icommon/driver -Iuser/include -Icommon/mqtt/include -Icommon/temperature/include -Icommon/driver/include  -Ic:/Espressif/ESP8266_SDK_151/include -Ic:/Espressif/ESP8266_SDK_151/include/driver -Ic:/Espressif/ESP8266_SDK_151/driver -Os -g -O2 -Wmissing-prototypes -Wpointer-arith -Wundef -Werror -Wno-implicit -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals  -D__ets__ -DICACHE_FLASH -c user/output.c -o build/user/output.o

其中定义选项 USE_OUTPUTS 设置为 1,但编译器从 #pragma 输出此消息:

    user/output.c:56:9: note: #pragma message: No Outputs
 #pragma message "No Outputs"
     ^

有人可以帮我看看我做错了什么吗?

最佳答案

#ifdef USE_OUPUTS

这表示OUPUTS,而不是OUTPUTS。您检查的宏名称错误。

关于c - 如何让 GCC (Xtensa 5.1) 识别定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38528749/

相关文章:

c - 调用 clFinish() 时 OpenCL 无效命令队列

C++ "...does not name a type"

gcc - 如何在 Ubuntu 上使用 DSFML2 和 D2 解决链接器错误?

c - PowerPC 程序集中的 "ifdef"

c# - #if 库的编译指令

c - 这是什么?获取proccount

c - 这样的代码合法吗?

c++ - vector * matrix 乘积效率问题

c - 使用 pthread 和 arm-linux-gnueabihf-gcc 的段错误

unit-testing - 条件编译是单元测试的有效模拟/ stub 策略吗?