How to compile C program on command line using MinGW?

178,828

Solution 1

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

Solution 2

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.

Solution 3

First:

Add your minGW's bin folder directory ( ex: C\mingw64\bin ) in System variables => Path. visual example


Compile:

.c: gcc filename.c -o desire

.cpp: g++ filename.cpp -o desire


Run:

desire/ or ./desire

Solution 4

Just set the environment variable to the EXACT path to gcc.exe like this:

C:\Program Files (x86)\CodeBlocks\MinGW\bin\gcc.exe

Solution 5

I encountered the same error message after unpacking MinGW archives to C:\MinGW and setting the path to environment variable as C:\MinGW\bin;.

When I try to compile I get this error!

gcc: error: CreateProcess: No such file or directory

I finally figured out that some of the downloaded archives were reported broken while unpaking them to C:\MinGW (yet I ignored this initially). Once I deleted the broken files and re-downloaded the whole archives again from SourceForge, unpacked them to C:\MinGW successfully the error was gone, and the compiler worked fine and output my desired hello.exe.

I ran this:

gcc hello.c -o hello

The result result was this (a blinking underscore):

_

Share:
178,828
Finding Nemo 2 is happening.
Author by

Finding Nemo 2 is happening.

Updated on January 10, 2020

Comments

  • Finding Nemo 2 is happening.
    Finding Nemo 2 is happening. over 4 years

    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?