gcc compiler error with -D option-Collection of common programming errors
I’ve written a makefile that compiles multiple files. when executing a line like this :
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
It generates a huge list of errors:
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
but when I remove -D FILE it compiles just fine. what is this about ??
EDIT1: the same #define FILE works fine when I use codeblocks for example. why so ??
-
FILE
is already used in C as a file pointer object (see thefopen(3)
manpage).You will need to choose a different name for that constant.
The actual error is caused by the declaration of functions like
fopen()
:FILE *fopen(const char *restrict filename, const char *restrict mode);
being turned into:
*fopen(const char *restrict filename, const char *restrict mode);
because you defined
FILE
to nothing.EDIT Actually it’s probably causing an issue in the declaration of
FILE
itself, and not thefopen()
et al functions:typedef struct __sFILE { ... } FILE;
Where
FILE
is replaced with nothing.
Originally posted 2013-11-27 12:27:10.