How to compile C program on command line using MinGW?

c, command-line, gcc, mingw, windows

Solution

It indicates it couldn't find `gcc.exe`.

I have a path environment variable set to where MinGW is installed

Maybe you haven't set the path correctly?

echo %path%

does that include the path to gcc.exe? Otherwise, compilation is similar to Unix:

gcc filename.c -o filename

Problem

What command does one have to enter at the command line in Windows 7 to compile a basic C program? Like I am literally wondering what you type in the command prompt, to compile a .c file. I tried: ``` > gcc foo.c ``` But it says: ``` 'gcc' is not recognized as an internal or external command, operable program or batch file. ``` I also tried: ``` > minGW foo.c ``` But I got back: ``` 'minGW' is not recognized as an internal or external command, operable program or batch file. ``` I have a path environment variable set to where MinGW is installed: ``` C:\Program Files (x86)\CodeBlocks\MinGW\bin ``` I can't really find any information on where I'm going wrong, and can't find anything in the official MinGW documentation, as it seems like this is something so simple, sort of an embarrassing question, that it's figured people know what to do?

Original source