This wikiHow teaches you how to compile a C program from source using the GNU Compiler (GCC) for Linux and Minimalist Gnu (MinGW) for Windows.
Steps
Method 1 of 2: Using GCC for Unix

Step 1. Open a terminal window on your Unix system

Step 2. Type gcc --version and press ↵ Enter
This should return the version number of the C compiler. If the command is unknown, chances are that GCC is not installed.
- If not installed, see the documentation for your Linux distribution to learn how to get the correct package.
- If you want to compile a C++ program, use 'g++' instead of 'gcc'.

Step 3. Navigate to the directory where you saved the source code
For example, if the source file, 'main.c' is located in /usr/wikiHow/source, you would type cd /usr/wikiHow/source

Step 4. Type gcc main.c –o HelloWorld
Replace 'main.c' with the name of the source file, and 'HelloWorld' with the name of your program. The program is then compiled.
- If you get errors and want more information about them, use gcc -Wall -o errorlog file1.c. Then view the file 'errorlog' in the current directory, with cat errorlog.
- To compile one program from multiple source files, use gcc -o outputfile file1.c file2.c file3.c.
- To compile multiple programs simultaneously from multiple source files, use gcc -c file1.c file2.c file3.c.

Step 5. Run your compiled program
Type./HelloWorld but replace 'HelloWorld' with the name of your program.
Method 2 of 2: Using MinGW for Windows

Step 1. Download Minimalist GNU for Windows (MinGW)
This is an easy to install version of GCC for Windows. You can download the installation file from

Step 2. Run the MinGW installation file
If the file doesn't open by itself, double-click it in your downloads folder, then click 'Install'

Step 3. Select your installation preferences and click Continue
MinGW recommends using the default installation folder (C:\MinGW). If you need to change the folder, don't use a folder with spaces in its name (such as "Program Files")

Step 4. Select the compilers to install
- In any case, choose Basic Setup in the left pane, and check the desired compilers in the main pane on the right.
- Advanced users can choose All Packages and select additional compilers.

Step 5. Click the Installation menu
This is located at the top left of the MinGW window.

Step 6. Click Apply Changes

Step 7. Click Apply
The compilers are now downloaded and installed.

Step 8. Add the path to MinGW to your system's environment variables
Do this as follows:
- Press ⊞ Win+S to select Search, and type environment.
- click on Editing system environment variables in the search results.
- click on Environment variables
- click on To process under the top box (under 'User Variables')
- Scroll to the bottom of the Variable Value box.
- Type;C:\MinGW\bin immediately after the last letter in the box. Note: if you installed MinGW in a different directory, type;C:\path-to-that-directory\bin.
- click on OK and then again OK. Click on the remaining OKbutton to close the window.

Step 9. Open Command Prompt as administrator
You do this as follows:
- Press ⊞ Win+S and type cmd.
- Right click on Command Prompt in the search results, and after Run as administrator.
- click on Yes to confirm the changes.

Step 10. Navigate to the folder where you saved the source code
For example, if your source code is called helloworld.c and is located in C:\Source\Programs, then type cd C:\Source\Programs

Step 11. Type gcc helloworld.c –o helloworld.exe
Replace 'helloworld' with the name of your source code and application. Once the program has been compiled, you will return to the command prompt without any errors.
Any errors in the code that are indicated must first be corrected before the program will compile

Step 12. Type the name of your program to run it
If it's called helloworld.exe, you type that into the command line to start the program.
Tips
- Compiling your source code with a -g flag will generate debug information that the corresponding debug program (GDB) can use to make debugging easier.
- A 'makefile' can be created to make it easier to compile large programs.
- If you use optimization a lot, keep in mind that optimization for speed can come at the expense of size and sometimes accuracy, and vice versa.
- When compiling a C++ program, use G++ in the same way as GCC. Remember that C++ files have the extension '.cpp', instead of '.c'.