Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile C program on command line using MinGW?

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?

like image 847
Finding Nemo 2 is happening. Avatar asked May 19 '12 01:05

Finding Nemo 2 is happening.


People also ask

How do I compile a program in MinGW?

To avoid giving the complete path each time you want to compile a program, you can add the MinGW's bin directory to the path variable of FireCMD. To do this you can give this command: path -a. This will open Browse for Folder dialog box from where you will be able to select the directory.


2 Answers

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 
like image 98
P.P Avatar answered Oct 11 '22 22:10

P.P


I've had this problem and couldn't find why it kept happening. The reason is simple: Once you have set up the environment paths, you have to close the CMD window, and open it again for it be aware of new environment paths.

like image 45
Herz3h Avatar answered Oct 11 '22 20:10

Herz3h