[Setup] C Language Development Environment
To write and run C programs, you need a compiler — a tool that converts source code into an executable file. This page walks you through setting up a C development environment on both Windows and macOS.
Setting Up on Windows
There are several ways to use C on Windows.
| Method | Description |
|---|---|
| MinGW (gcc) | A lightweight compiler. You can easily compile and run code from the command line. |
| Visual Studio | Microsoft's integrated development environment. Suitable for large-scale development as well. |
Installing MinGW
MinGW is a tool that makes GCC (GNU Compiler Collection) available on Windows.
- Download the installer from mingw-w64.org.
- After installation, add the MinGW
binfolder to thePATHenvironment variable. - Run the following in Command Prompt to verify the installation.
gcc --version
If version information is displayed, the installation is complete.
Setting Up on macOS
On macOS, installing Xcode Command Line Tools makes gcc and clang immediately available. Run the following command in Terminal.
xcode-select --install
When a dialog appears, click "Install". After it completes, you can verify with the following command.
gcc --version
Compiling and Running
A C program follows this workflow: write source code → compile → run.
1. Create the source file
Use a text editor to create a file named hello.c with the following content.
#include <stdio.h>
int main(void) {
printf("Hello, World!\n");
return 0;
}
2. Compile
Run the following in Terminal (or Command Prompt).
gcc hello.c -o hello
-o hello specifies the output filename. If omitted, the output will be named a.out (or a.exe on Windows).
3. Run
For macOS / Linux:
./hello
For Windows:
hello.exe
If Hello, World! is displayed, you're all set.
Commonly Used Compiler Options
| Option | Description |
|---|---|
| -o filename | Specifies the output filename. |
| -Wall | Enables all warnings. Useful for catching bugs early. |
| -g | Includes debug information. Use this when running with a debugger. |
| -std=c11 | Compiles using the C11 standard. Makes the target standard explicit. |
Example of compiling with warnings enabled.
gcc -Wall hello.c -o hello
As a beginner, it is recommended to always use -Wall when compiling. Warning messages will help you catch bugs.
If the Command Is Not Found
If your terminal displays gcc: command not found, the compiler may not be installed, or the PATH may not be configured correctly. Follow the steps below to check and fix the issue.
For macOS
On macOS, installing Xcode Command Line Tools makes gcc available. Run the following command.
xcode-select --install
After installation, verify it.
gcc --version
For Linux / Windows (MinGW)
Check where the gcc command is located.
which gcc
If not found, check common installation locations.
ls /usr/bin/gcc ls /usr/local/bin/gcc
Once you know the location of the command, add the PATH to your shell configuration file. First, check which shell you are using.
echo $SHELL
If /bin/zsh is shown, edit ~/.zshrc; if /bin/bash is shown, edit ~/.bashrc.
For macOS (zsh):
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
For Linux (bash):
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc source ~/.bashrc
For Windows (MinGW), go to "Advanced System Settings" → "Environment Variables" → "Path" and add the MinGW bin folder (e.g., C:\MinGW\bin or C:\mingw-w64\bin).
If you find any errors or copyright issues, please contact us.