导读 GNU Compiler Collection (GCC)是由C、C++、Objective-C、Fortran、Ada、Go和D等编程语言的编译器和库组成,很多开源项目,包括Linux内核和GNU工具,都是用GCC编译的。

CentOS默认资源库中包含一个名为"开发工具"的软件包组,其中包括 GNU 编译器集合、GNU 调试器以及其他编译软件所需的开发库和工具。

安装GCC与配置GCC

要安装GCC开发工具包,必须要以root或具有sudo权限的用户身份运行以下命令,我这里是以root用户的身份执行命令安装的,具体安装如下:

安装开发工具组
[root@ece2cd92dada ~]# dnf group install "Development Tools"

以上命令安装了很多软件包,包括gcc、g++和make

安装开发工具手册
[root@ece2cd92dada ~]# dnf install man-pages

验证GCC是否安装成功
[root@ece2cd92dada ~]# gcc --version
gcc (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

vim编写一个C语言的“Hello World”
[root@ece2cd92dada ~]# vim hello.c
#include 
int main()
{
  printf ("Hello World!\n");
  return 0;
}
GCC编译hello.c文件,生成hello二进制程序
[root@ece2cd92dada ~]# gcc hello.c -o hello

运行编译后的hello二进制程序
[root@ece2cd92dada ~]# ./hello 
Hello World!

结论

本文介绍了如何在CentOS 8上安装GCC开发编译工具,现在可以访问官方的GCC文档页面,也可以查阅一些资料,学习如何使用GCC和G++来编译你的C和C++程序。

本文原创地址:https://www.linuxprobe.com/centos8-install-gcc.html编辑:向云艳,审核员:逄增宝