Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. C Language Dictionary
  3. [Setup] C Language Development Environment

[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.

MethodDescription
MinGW (gcc)A lightweight compiler. You can easily compile and run code from the command line.
Visual StudioMicrosoft'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.

  1. Download the installer from mingw-w64.org.
  2. After installation, add the MinGW bin folder to the PATH environment variable.
  3. 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

OptionDescription
-o filenameSpecifies the output filename.
-WallEnables all warnings. Useful for catching bugs early.
-gIncludes debug information. Use this when running with a debugger.
-std=c11Compiles 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 .