gcc:-Dvar=未按预期工作的值

gcc:-Dvar=未按预期工作的值,gcc,Gcc,我试图编译一个具有以下行的库: #if AE_OS==AE_WINDOWS #include windows.h //stuff #elif AE_OS==AE_POSIX //other stuff #endif 当我使用cpp-DAE_OS=AE_POSIX cpp/src/ap.cpp:63:21: fatal error: windows.h: No such file or directory #include <windows.h>

我试图编译一个具有以下行的库:

#if AE_OS==AE_WINDOWS
#include windows.h
//stuff
#elif AE_OS==AE_POSIX
//other stuff
#endif
当我使用
cpp-DAE_OS=AE_POSIX

cpp/src/ap.cpp:63:21: fatal error: windows.h: No such file or directory
 #include <windows.h>
                     ^
我也尝试过
-D“AE_OS AE_POSIX”
认为这与
#定义“AE_OS AE_POSIX”
相同,但显然它忽略了引号,因为它将
AE_OS
定义为1:

<command-line>:0:16: error: missing binary operator before token "1"
cpp/src/ap.cpp:65:7: note: in expansion of macro ‘AE_OS’
 #elif AE_OS==AE_POSIX
:0:16:错误:标记“1”之前缺少二进制运算符
cpp/src/ap.cpp:65:7:注意:在宏“AE_OS”的扩展中
#elif AE_OS==AE_POSIX

正确的方法是什么?

预处理器理解整数类型的表达式,而不是字符串

AE_POSIX和AE_窗口作为不同的整数:

/*
 * definitions
 */
#define AE_UNKNOWN 0
#define AE_MSVC 1
#define AE_GNUC 2
#define AE_SUNC 3
#define AE_INTEL 1
#define AE_SPARC 2
#define AE_WINDOWS 1
#define AE_POSIX 2
因此,对于POSIX,请执行以下操作:

cpp -DAE_OS=2
cpp -DAE_OS=2