Search code examples
c++makefileg++mingwmingw32

"Bad command or file name" error when compiling with g++ using Make


I recently installed MinGW and learnt how to use Make. But I get an error whenever I try to compile a CPP source file using make. Below is the output:

MAKE Version 3.6  Copyright (c) 1991 Borland International

Available memory 33397872 bytes

        mingw32-g++ main.cpp --std=c++11 -o program
Bad command or file name

The main.cpp is a very simple "Hello World" type program. The command works when I use it in the Command Prompt directly.
I am running Windows 8.1 with MinGW. GCC version 4.8


Solution

  • As another respondent has noted, you should not be trying to coax Borland's antique make into working with MinGW; the most appropriate option for you would be either mingw32-make, (a native windows build of GNU make suitable for use directly from a cmd.exe shell session), or install MinGW.org's MSYS, and use the make which it provides; either of these may be installed using MinGW.org's mingw-get installation manager.

    Either of these options should work for you, while avoiding the bloat of Cygwin, (or the equally bloated MSYS2, which should not be confused with the MinGW.org MSYS product). Do note that, if you choose the MSYS option, you will be installing a very light-weight fork of an old, but still perfectly adequate and capable, version of Cygwin.

    In closing, to clear up your evident confusion, I would also point out that the g++.exe which you find in the $MINGW32_ROOT/bin directory, and the mingw32-g++.exe to which you refer, are one and the same -- both are the MinGW compiler, and you would normally invoke it simply as g++.