
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人
1.2.2 实践步骤
我们将会安装一个功能包集或功能包组,也就是一个包含其他包集合的包。这个功能包集包含GCC、GNU Make、一些手册页,以及一些其他的程序和库,它们对于开发非常有用。
1.2.2.1 基于Debian的系统
以下操作适用于所有基于Debian的系统,例如Debian、Ubuntu和Linux Mint。
1.更新存储库缓存以获取下一步中所需的最新版本:

2.安装build-essential包,并在提示时回答y:

1.2.2.2 基于Fedora的系统
以下操作适用于所有基于Fedora的系统,例如Fedora、CentOS和Red Hat。
安装Development Tools软件套件:

1.2.2.3 基于Debian和Fedora系统验证安装
以下操作同时适用于Debian和Fedora系统。
1.通过查询安装的版本来验证安装是否成功。请注意,确切的版本信息可能会因系统不同而存在差异,这是正常现象:

2.通过编译一个小型C程序来试用GCC编译器。请在编辑器中输入源代码并将其保存为first-example.c。该程序将在终端上打印"Hello, world!":

3.使用GCC编译它。此命令将会生成一个名为a.out的文件:

4.尝试运行该程序。为了在Linux上运行常用二进制文件目录外(/bin、/sbin、/usr/bin等)的程序,你需要在文件名前键入一个特殊的./序列。这将从当前路径执行程序:

5.重新编译程序。这一次,我们将使用-o选项(-o表示输出)为程序编译生成的文件指定一个名字。这一次,程序编译所生成的文件名为first-example:

6.重新运行程序,这一次使用新名字first-example:

7.使用Make来编译程序:

8.再次运行程序:
