1. Starting with Hello World: How Does a Program Become an Executable File?
Let’s start with the simplest C program:

On Linux, to run this code, we need to use GCC to turn it into a program that the machine can execute. This process consists of 4 steps:
-
Preprocessing (
<span>hello.c</span>→<span>hello.i</span>): Handling preprocessing directives like<span>#include</span>. -
Compilation (
<span>hello.i</span>→<span>hello.s</span>): Generating assembly code. -
Assembly (
<span>hello.s</span>→<span>hello.o</span>): Generating machine code (object file). -
Linking (
<span>hello.o</span>→<span>hello</span>): Merging the object file and libraries into an executable file.
With GCC, this can be done in one command:

But in Windows Visual Studio, you just need to click the “Build” button—because VS is an IDE, which packages the compiler, build tools, and debugger, hiding these details.
2. GNU and GCC: Cornerstones of the Free Software Movement
What is GNU?
-
Full name: “GNU’s Not Unix” (recursive acronym), initiated by Richard Stallman in 1983.
-
Goal: To create a completely free operating system (later combined with the Linux kernel to form GNU/Linux).
-
Spirit: “Software should be free to use, modify, and share” (GPL license).

(The logo of GNU is an African antelope, symbolizing freedom to run.)
What is GCC?
-
GNU Compiler Collection (GNU Compiler Collection).
-
Supports multiple languages including C, C++, Fortran, etc.
-
Default compiler for Linux and the compilation standard in the open-source world.

3. Compilation Choices on Windows: MinGW vs MSVC
MinGW: The Windows Version of GCC
-
Full name: Minimalist GNU for Windows.
-
Features:
-
Ports GCC to Windows.
-
Generates native
<span>.exe</span>, without relying on additional DLLs. -
Open source and free (commonly used by Qt, GTK, etc.).

MSVC: Microsoft’s Favorite
-
Microsoft Visual C++, integrated into Visual Studio.
-
Features:
-
Best compatibility with Windows.
-
Closed source but free (Community Edition).
-
Deeply integrated with Windows SDK.

| MinGW (GCC) | MSVC | |
|---|---|---|
| Origin | GNU Open Source | Microsoft Official |
| Speed | Medium | Better Optimization |
| Ecology | Cross-Platform | Windows Exclusive |
4. Why Do We Need Build Tools? From Make to Ninja
Make: The Earliest “Smart Batch Processing” Tool
-
Problem: When a project has
<span>a.c</span>,<span>b.c</span>,<span>lib.c</span>, etc., manually typing the<span>gcc</span>command is too cumbersome. -
Solution: Define rules using
<span>Makefile</span>.


CMake: A Cross-Platform Makefile Generator
-
New Problem: Different platforms require different Makefiles (Windows uses
<span>nmake</span>, Linux uses<span>make</span>, etc.). -
Solution: Use CMake to generate build files for the corresponding platform.

Generating Makefile:

Ninja: Fast and Efficient from Google
-
Optimized for very large projects (like Chrome, LLVM).
-
10 times faster than Make (starts compiling 30,000 files in 1 second).
-
Usually generated automatically by CMake as
<span>build.ninja</span>.

5. Recommended Modern C/C++ Development Toolchains
| Scenario | Recommended Toolchain |
|---|---|
| Linux Development | GCC + CMake + Ninja |
| Native Windows Development | MSVC + Visual Studio |
| Cross-Platform Projects | MinGW/Clang + CMake + Ninja |
| Very Large Projects | Clang + CMake + Ninja |
Conclusion: A Diagram to Clarify Relationships
Key Takeaways:
-
GCC is an open-source compiler, while MSVC is Microsoft’s.
-
Make is still going strong, while Ninja has emerged as a strong contender.
-
CMake is not a compiler; it is a “tool for generating build files.”
Now you can confidently battle the <span>undefined reference</span><span> error for three hundred rounds!</span>
