4

I recently installed mingw-w64 to learn c without needing cygwin. The issue is that mingw32-make is using g++ to compile my .c source, but I don't really know why. The behavior is illustrated here:

here's the source:

#include <stdio.h>
int main(int argc, char *argv[])
{
    puts("Hello world.");
    return 0;
}

here's the makefile:

CC = gcc -O
CFLAGS=-Wall -g
clean:
    rm -f hello_world

using gnuwin32 version of make:

-> make hello_world
gcc -O -Wall -g    hello_world.c   -o hello_world

using mingw32-make:

-> mingw32-make hello_world
g++     hello_world.c   -o hello_world

Can someone explain this, or know why its happening? Using Cygwin, and also using Linux, the make tool uses a c-compiler (usually cc) as expected. Why does mingw32-make use g++, instead of gcc. gcc is installed in the bin directory.

mingw-w64 is the latest winbuild as of 2 days ago

2
  • You might try using -x c to force C compilation. Add it to your CFLAGS. You could also add CXX = gcc -O to your makefile. If its not honored too, then it might help isolate the problem further.
    – jww
    Feb 16, 2015 at 0:25
  • Thanks for the input. using "CFLAGS=-Wall -g -x c" does not induce the desired behavior, but using CXX = gcc -O does result in using gcc as the compiler. I guess that is just telling make to compile c++ files with gcc? A bit of a hack I suppose.
    – Vince W.
    Feb 16, 2015 at 3:01

2 Answers 2

4

mingw32-make (correctly IMO) treats the file system as case insensitive, so foo.c and FOO.C refer to the same file.

Your makefile lacks any explicit rule for your hello_world goal, so built-in implicit rules must be used; it seems that the COMPILE.C rule is being matched for hello_world.c, before the COMPILE.c rule; COMPILE.C is a default rule for compiling C++, so the appropriate compiler is used.

As you note, setting CXX = gcc is kludgy, and fundamentally wrong; it will break if your project expands to requiring mixed C and C++ components. A more appropriate solution is to provide your own rule ... either an explicit rule, or a pattern rule, to direct mingw32-make to use $(CC) for compiling *.c (and *.C) files, so that the built-in default rules will not apply. You can then keep CXX = g++ for compiling any *.cpp files, (recommended for compatibility with MSVC convention), which your project may include.

1
  • 1
    That said, MinGW developers don't really like mingw32-make; we advocate the use of MinGW.org's complementary MSYS platform tools, and the make which they include, as a better alternative. Mar 10, 2015 at 9:24
2

This has been confirmed to be a problem inside GNU Make, present in builds that enabled the case-insensitive filesystem option. It has also been fixed in the repository.

The solution is either to use a GNU Make build that doesn't have the case-insensitve filesystem option (--enable-case-insensitive-file-system / HAVE_CASE_INSENSITIVE_FS) enabled, or using the latest sources (this revision or newer), where the issue is fixed.

Further references:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.