I recently upgraded my GCC (MinGW) to version 4.8.1 and encounter a problem with -D option. For example, the following main.c code
#include <stdio.h>
int main(void) {
printf("Hello world!\n");
#ifdef TEST
printf("We are in testing mode!\n");
#endif // TEST
return 0;
}
prints
Hello world
when I type:
gcc -DTEST main.c -o main.exe
but the following two work:
gcc -DTEST= main.c -o main.exe
gcc -DTEST=1 main.c -o main.exe
My previous version of GCC (I believe 4.6) does not have this problem. Is this a bug?
The following is the edited output dump for gcc -v -DTEST -E -dM -c main.c
. Notice the #define test 1
.
...
#define STDOUT_FILENO 1
#define test 1
#define _PID_T_
#define __LDBL_MIN_EXP__ (-16381)
...
Using built-in specs.
COLLECT_GCC=c:\MinGW\bin\gcc.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=m
ingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto
--enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++
,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-l
ibstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gm
p-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --
with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-
libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/
mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)
COLLECT_GCC_OPTIONS='-v' '-D' 'TEST' '-E' '-dM' '-c' '-mtune=generic' '-march=pe
ntiumpro'
c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/cc1.exe -E -quiet -v -iprefix c:\ming
w\bin\../lib/gcc/mingw32/4.8.1/ -D TEST main.c -mtune=generic -march=pentiumpro
-dM
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/inclu
de"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../..
/../../include"
ignoring nonexistent directory "/mingw/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/inclu
de-fixed"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../..
/../../mingw32/include"
ignoring nonexistent directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../include
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include-fixed
c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../mingw32/include
End of search list.
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/;c:/mingw/bin/../libexec
/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.8.1/;c:/mingw/bin/../lib/gcc/;c:/
mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/;c:/mingw/bin/../lib/
gcc/mingw32/4.8.1/../../../
COLLECT_GCC_OPTIONS='-v' '-D' 'TEST' '-E' '-dM' '-c' '-mtune=generic' '-march=pe
ntiumpro'
gcc -v -DTEST -E -dM -c main.c
into your question.#define
, but it is made small letters. That is the reason my compilation does not work. If I used-DTEST=
, then it is in capital. I still think my GCC version has bug. The output is quite lengthy. How do I post it?TEST
(it shows it in theCOLLECT_GCC_OPTIONS
output) - I don't know what would cause it to lowercase it in the preprocessor. I got my MinGW from nuwen.net/mingw.html You might want to ask whoever provided the MinGW you're using if they have any idea what's going on. I'm leaning toward a bug in your build at this point rather than something in your environment, which is what I was guessing before.gcc -DFOOBAR -E -dM -c main.c | grep -i foobar
DoesFOOBAR
become lowercase?