This article is generated by Tencent Yuanbao, with content outline and verification provided by @Xiao Hui~
GCC (GNU Compiler Collection) is a powerful open-source compiler suite that supports multiple programming languages, such as C, C++, Fortran, and more. It is not only the de facto standard compiler on Linux systems but is also widely used on other operating systems. This article will introduce the origin and significance of GCC, the method to install it using yum on Linux, and demonstrate the basic usage of GCC through a simple “Hello World” example.
1. The Origin and Importance of GCC
GCC originated in 1987, developed by Richard Matthew Stallman for the GNU project, aiming to create a completely free operating system compiler. Initially, it only supported the C language (GNU C Compiler), but it gradually expanded to support C++, Fortran, Ada, and other languages, and was renamed GNU Compiler Collection.
The importance of GCC is reflected in:
- Foundation of Open Source and Free Software: GCC follows the GPL license and is a core tool of the free software movement, allowing users to freely use, modify, and distribute.
- Cross-Platform Support: It supports various operating systems (such as Linux, Windows, macOS) and hardware architectures (such as x86, ARM, PowerPC), and can perform cross-compilation.
- Core of System Development: GCC is the preferred compiler for compiling the Linux kernel, numerous open-source software, and commercial projects, with trusted performance optimization and code generation quality.
2. Installing GCC Using yum on Linux
On RPM-based Linux distributions (such as CentOS, Fedora), you can easily install GCC using the <span>yum</span> package manager. <span>yum</span> can automatically handle dependencies.
-
Update yum cache (optional, recommended):
sudo yum updateThis ensures that you get the latest package information.
-
Install GCC:
sudo yum install gccThe system will automatically install GCC and all its dependencies.
-
Verify Installation: After installation, check the GCC version with the following command to confirm successful installation:
gcc --version
3. A Simple Hello World Example
Below is a simple “Hello World” program demonstrating the basic usage of GCC.
-
Write Source Code: Create a file named
<span>hello.c</span>with the following content:#include <stdio.h> int main() { printf("Hello, World!\n"); return 0; } -
Compile Source Code: Use GCC to compile
<span>hello.c</span>and specify the output executable file name as<span>hello</span>:gcc hello.c -o hello
<span>hello.c</span>: Source file.<span>-o hello</span>: Specifies the output executable file name as<span>hello</span>. If the<span>-o</span>option is not used, the default executable file name will be<span>a.out</span>.
Run the Program: After successful compilation, run the generated executable file:
./hello
The terminal will output:
Hello, World!
Conclusion
As a powerful, open-source, cross-platform compiler suite, GCC is a cornerstone in software development, especially in Linux system development and the free software ecosystem. Installing GCC on yum-based Linux systems is very straightforward. Through the most basic “Hello World” program, you can quickly experience how GCC compiles source code into executable programs.