GCC(GNU Compiler Collection)是一个流行且广泛使用的开源编译器,支持许多编程语言,包括C,C++和Objective-C。它可以在许多不同的平台上使用,包括Linux,macOS和Windows。GCC 以其高优化能力和对许多架构和平台的支持而闻名。
在 Rocky Linux 9 上安装 GCC
第 1 步。第一步是将系统更新到最新版本的软件包列表。为此,请运行以下命令:
<span class="pln">sudo dnf check</span><span class="pun">-</span><span class="pln">update sudo dnf update</span>
第 2 步。在 Rocky Linux 9 上安装 GCC。
默认情况下,GCC 在 Rocky Linux 9 AppStream 存储库中可用。现在我们使用以下命令安装最新版本的 GCC:dnf
<span class="pln">sudo dnf install gcc</span>
此命令将在您的系统上下载并安装 GCC 编译器以及所需的任何依赖项。
要验证系统上是否安装了 GCC,请使用以下命令:
<span class="pln">gcc </span><span class="pun">--</span><span class="pln">version</span>
输出:
<span class="pln">gcc </span><span class="pun">(</span><span class="pln">GCC</span><span class="pun">)</span> <span class="lit">11.2</span><span class="pun">.</span><span class="lit">1</span> <span class="lit">20210728</span> <span class="pun">(</span><span class="typ">Red</span> <span class="typ">Hat</span> <span class="lit">11.2</span><span class="pun">.</span><span class="lit">1</span><span class="pun">-</span><span class="lit">1</span><span class="pun">)</span> <span class="typ">Copyright</span> <span class="pun">(</span><span class="pln">C</span><span class="pun">)</span> <span class="lit">2022</span> <span class="typ">Free</span> <span class="typ">Software</span> <span class="typ">Foundation</span><span class="pun">,</span> <span class="typ">Inc</span><span class="pun">.</span> <span class="typ">This</span> <span class="kwd">is</span><span class="pln"> free software</span><span class="pun">;</span><span class="pln"> see the source </span><span class="kwd">for</span><span class="pln"> copying conditions</span><span class="pun">.</span> <span class="typ">There</span> <span class="kwd">is</span><span class="pln"> NO warranty</span><span class="pun">;</span> <span class="kwd">not</span><span class="pln"> even </span><span class="kwd">for</span><span class="pln"> MERCHANTABILITY </span><span class="kwd">or</span><span class="pln"> FITNESS FOR A PARTICULAR PURPOSE</span><span class="pun">.</span>
第 3 步。测试 GCC 编译器。
为了测试GCC编译器,我们将编写一个简单的C程序,将“Hello,World Meilana!”打印到控制台。这是代码:
<span class="com">#include</span> <span class="kwd">int</span><span class="pln"> main</span><span class="pun">()</span> <span class="pun">{</span><span class="pln"> printf</span><span class="pun">(</span><span class="str">"Hello, World Meilana!\n"</span><span class="pun">);</span> <span class="kwd">return</span> <span class="lit">0</span><span class="pun">;</span> <span class="pun">}</span>
将此代码保存在名为 的文件中。hello.c
现在,打开终端并导航到保存文件的目录。运行以下命令编译代码:hello.c
<span class="pln">gcc </span><span class="pun">-</span><span class="pln">o hello hello</span><span class="pun">.</span><span class="pln">c</span>
这将创建在同一目录中命名的可执行文件。若要运行该程序,请键入以下命令:hello
<span class="pun">./</span><span class="pln">hello</span>
您应该在终端中看到以下输出:
<span class="typ">Hello</span><span class="pun">,</span> <span class="typ">World</span> <span class="typ">Meilana</span><span class="pun">!</span>
感谢您使用本教程在您的 Rocky Linux 9 系统上安装 GCC(GNU 编译器集合)。有关其他帮助或有用信息,我们建议您查看 GCC 官方网站。