从compile传递的宏无法在eclipse中解析

macro passed from compile cannot be resolved in eclipse

本文关键字:eclipse compile      更新时间:2023-10-16

我试图在编译时像这样传递一个定义好的宏给我的程序:

#include <stdio.h>
int main() {
    // KEY_CNT is not defined in program but passed at compile time
    printf("KEY_CNT: %d", KEY_CNT); 
    return 0;
}

并使用g++ -DKEY_CNT=2 -O2 test_3.cpp -o test_3编译,它按预期工作,但问题是Eclipse无法解决'KEY_CNT'。这只是一个玩具的例子,在我最初的程序中,很多像这样的错误是很烦人的。

我认为Eclipse可能需要通知我的编译选项,以便它知道'KEY_CNT'被定义,所以我在Properties -> C/C++ Build -> Settings -> GCC C++ Compiler -> Miscellaneous中添加-DKEY_CNT=2,但它仍然不起作用。

有什么建议来解决这个问题吗?

========添加========

Eclipse版本:Eclipse IDE for C/c++ Developers, Luna Service Release 2 (4.4.2)

Properties -> C/c++ Build -> Settings -> GCC c++ Compiler -> Miscellaneous

错误的地方。

应该是"C/c++ Build -> Settings -> GCC c++ Compiler -> Preprocessor"

刚刚验证可以