我写了一个编译多个文件的makefile。执行这样的行时:
g++ -c -Wall -U DEBUG -U FILE -U HighPriority -U OnlyCUDA -U CUDA -U THREAD_NUM -U SIZE -U InputFileName -D FILE -D SIZE=32 -D THREAD_NUM=4 -D CUDA -D InputFileName=input/In32.txt ../src/lib/Globals.cpp -o Globals.o
它会产生大量错误:
In file included from /usr/include/wchar.h:36:0,
from /usr/include/c++/4.6/cwchar:46,
from /usr/include/c++/4.6/bits/postypes.h:42,
from /usr/include/c++/4.6/iosfwd:42,
from /usr/include/c++/4.6/ios:39,
from /usr/include/c++/4.6/istream:40,
from /usr/include/c++/4.6/sstream:39,
from /usr/include/c++/4.6/complex:47,
from ../src/lib/../inlcude/Globals.h:3,
from ../src/lib/Globals.cpp:1:
/usr/include/stdio.h:48:25: error: expected unqualified-id before numeric constant
但是当我删除-D FILE时,它编译得很好。这是什么意思?
EDIT1: 例如,当我使用代码块时,相同的#define FILE工作正常。为什么呢?
答案 0 :(得分:3)
FILE
已在C中用作文件指针对象(请参阅fopen(3)
联机帮助页)。
您需要为该常量选择一个不同的名称。
实际错误是由fopen()
:
FILE *fopen(const char *restrict filename, const char *restrict mode);
变成:
*fopen(const char *restrict filename, const char *restrict mode);
因为您将FILE
定义为 nothing 。
编辑实际上,它可能会在FILE
本身的声明中引起问题,而不是fopen()
等函数:
typedef struct __sFILE {
...
} FILE;
FILE
替换为 nothing 。
答案 1 :(得分:1)