How to compile C program on command line using MinGW? How to compile C program on command line using MinGW? windows windows

How to compile C program on command line using MinGW?


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


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.


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