PDF download Download Article PDF download Download Article

If you've written or downloaded some C code on your Windows PC, you'll need to compile the code to turn it into an program you can run. This simple wikiHow tutorial will walk you through compiling and running a C program from the Windows command prompt using MinGW, an easy-to-install version of the GCC compiler.

  1. If you haven't already done so, you'll need to install a C compiler on your PC to compile the C program . Compiling the C code will turn the code into an executable C program. MinGW is one of the easiest options to install for Windows:
    • Download MinGW from https://sourceforge.net/projects/mingw/ .
    • Double-click the downloaded file and follow the on-screen instructions to prepare the installation.
    • When you get to the MinGW Installation Manager window, you'll see several packages in the upper-right panel.
    • Check the boxes next to "mingw32-base" and "mingw-gcc-g++."
    • Click the Installation menu and select Apply Changes .
    • Click Apply .
  2. This step makes it easier to run the compiler from the command prompt, as you won't have to enter the full path to the GCC program. [1]
    • Press the Windows key and type environment . Click Edit the system environment variables in the search results. [2]
    • Click the Environment Variables… button.
    • Select the "Path" option under "System variables" and click Edit…
    • Click New .
    • Type C:\MinGW\bin and click OK .
    • Click OK and OK again.
    Advertisement
  3. Open a Command Prompt window as an administrator. To do this, press the Windows key, type cmd , right-click Command Prompt , and then select Run as Administrator . [3]
    • Once the prompt window is open, double-check that the compiler installed properly (and that the environment variables are set) by running the command gcc -- version at the prompt.
    • If you already had a command prompt window open, close it and open another so the path you added
  4. For example, if the program you want to compile is in C:\MyPrograms, type cd C:\MyPrograms and press Enter .
  5. The syntax you'll use is gcc filename.c -o filename.exe . This compiles the program and makes it executable. [4]
    • Replace filename.c with the name of the file containing your C code, and filename.exe with the name you want to give the compiled program.
    • Make sure you give the compiled program a name that ends with .exe .
    • The -o flag specifies the output file.
  6. For example, if you created a program called hello.exe , you can type hello or hello.exe . This runs your C program from the command prompt. [5]
  7. Advertisement


Expert Q&A

Ask a Question
      Advertisement

      Video

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!

      About This Article

      Article Summary X

      1. Install MinGW.
      2. Add the compiler path to your system environment variables.
      3. Open an elevated command prompt window.
      4. Enter the directory of the C code.
      5. Type gcc filename.c -o filename.exe and press Enter to compile.
      6. Run the program by typing its name and pressing Enter .

      Did this summary help you?
      Thanks to all authors for creating a page that has been read 292,759 times.

      Is this article up to date?

      Advertisement