How to compile C program on command line using MinGW?

Finding Nemo 2 is happening. picture Finding Nemo 2 is happening. · May 19, 2012 · Viewed 153k times · Source

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?

Answer

P.P picture P.P · May 19, 2012

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%

shows the path to gcc.exe? Otherwise, compilation is similar to Unix:

gcc filename.c -o filename