C ยท Chapter 2 of 45

C Install & Compiler Setup

To write and run C programs you need a compiler that translates your source code into an executable. Popular choices are GCC (GNU Compiler Collection), Clang, and MSVC on Windows.

On Linux, GCC is often preinstalled or installable via a package manager. On macOS, installing Xcode Command Line Tools gives you Clang. On Windows, MinGW or WSL are common ways to get GCC.

Syntax
gcc file.c -o file
./file

Installing GCC

On Ubuntu/Debian run `sudo apt install build-essential`. On macOS run `xcode-select --install`. On Windows, install MinGW-w64 or use WSL to get a Linux-like environment.

Editors and IDEs

VS Code with the C/C++ extension is a popular free choice. Code::Blocks and CLion are dedicated C/C++ IDEs that bundle a compiler and debugger.

Example 1 (bash)
gcc --version
Output
gcc (GCC) 13.2.0

Checks that GCC is installed and shows its version.

Example 2 (bash)
gcc hello.c -o hello
./hello
Output
Hello, World!

Compiles hello.c into an executable named hello, then runs it.

Key points

  • GCC and Clang are the most common free C compilers.
  • Compiling turns .c source files into a runnable executable.
  • VS Code, Code::Blocks and CLion all support C development.
  • WSL is a convenient way to get a Linux GCC toolchain on Windows.
๐Ÿ’ก Note: Always keep your compiler up to date to get the latest C standard support and bug fixes.

๐Ÿ“ Quick Quiz

1. Which command compiles hello.c into an executable named hello?

2. Which tool gives you Clang on macOS?

3. What does GCC stand for?