An Introduction to GCC - 1 Introduction (介绍)

本书旨在介绍GNU C和C++编译器(gcc和g++)的使用方法,涵盖程序编译、优化和调试的基础选项。适合熟悉其他系统但初次接触GNU编译器的程序员,提供GCC特性和历史背景的概述。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

An Introduction to GCC - 1 Introduction (介绍)

for the GNU Compilers gcc and g++
Brian Gough
Foreword by Richard M. Stallman

1 Introduction (介绍)

The purpose of this book is to explain the use of the GNU C and C++ compilers, gcc and g++. After reading this book you should understand how to compile a program, and how to use basic compiler options for optimization and debugging. This book does not attempt to teach the C or C++ languages themselves, since this material can be found in many other places (see section Further reading).
本书的目的是介绍 GNU C 和 C++ 编译器 (gccg++) 的用法。阅读了本书后,你应该能学会怎样编译一个程序和怎样使用用于优化和调试的基本编译器选项。本书不会教你 C 或 C++ 语言本身,因为这样的资料在许多地方都能找到 (参见进一步阅读)。

Experienced programmers who are familiar with other systems, but new to the GNU compilers, can skip the early sections of the chapters Compiling a C program, Using the preprocessor and Compiling a C++ program. The remaining sections and chapters should provide a good overview of the features of GCC for those already know how to use other compilers.
熟悉其他系统但初次接触 GNU 编译器的有经验的程序员可以略过本章的前面部分 编译 C 程序预处理编译 C++ 程序。本章剩下的部分和其它章节应该能够为已经知道怎样使用其他编译器的程序员提供一个 GCC 特征的较好的概貌。

1.1 A brief history of GCC (GCC 简史)

The original author of the GNU C Compiler (GCC) is Richard Stallman, the founder of the GNU Project.
GNU C 编译器 (GCC) 的原作者是 Richard Stallman,也是 GNU 项目的奠基者。

The GNU project was started in 1984 to create a complete Unix-like operating system as free software, in order to promote freedom and cooperation among computer users and programmers. Every Unix-like operating system needs a C compiler, and as there were no free compilers in existence at that time, the GNU Project had to develop one from scratch. The work was funded by donations from individuals and companies to the Free Software Foundation, a non-profit organization set up to support the work of the GNU Project.
GNU 项目开始于 1984 年,为了提升自由和计算机用户与程序员间的合作,意图创建一个作为自由软件的完整的类 Unix 操作系统。每个类 Unix 操作系统都有 C 编译器,而当时还没有自由编译器存在,GNU 项目不得不白手起家开发一个。开发工作由来自个人和公司给予自由软件组织 (Free Software Foundation) 的捐献资助,该组织是一个非营利的机构,是为支持 GNU 项目的工作而建立的。

The first release of GCC was made in 1987. This was a significant breakthrough, being the first portable ANSI C optimizing compiler released as free software. Since that time GCC has become one of the most important tools in the development of free software.
GCC 的第一版发行于 1987 年。作为以自由软件方式发行的第一个可移植的符合 ANSI C 标准的优化的编译器,这是一次重大突破。自此以后,GCC 就成为自由软件开发领域最重要的工具之一。

A major revision of the compiler came with the 2.0 series in 1992, which added the ability to compile C++. In 1997 an experimental branch of the compiler (EGCS) was created, to improve optimization and C++ support. Following this work, EGCS was adopted as the new main-line of GCC development, and these features became widely available in the 3.0 release of GCC in 2001.
GCC 编译器的一个主要修订版是 1992 年的 2.0 系列版本,它加入了编译 C++ 的能力。1997 年,GCC 编译器的的一个实验性分支 (EGCS) 被传建,以改善优化和对 C++的支持。随着这些工作的进展,EGCS 被采纳为 GCC 开发版本的新主线,这些特征也在 2001 年的 GCC 3.0 发行版中被广泛采用。

Over time GCC has been extended to support many additional languages, including Fortran, ADA, Java and Objective-C. The acronym GCC is now used to refer to the GNU Compiler Collection. Its development is guided by the GCC Steering Committee, a group composed of representatives from GCC user communities in industry, research and academia.
随着时间的流逝,GCC 被扩展以支持更多的语言,包括有 Fortran、ADA、Java 和 Object-C。GCC 这个缩略语现在是指 GNU Compiler Collection。它的开发由 GCC 指导委员会 (GCC Steering Committe) 管理。这是一个由业界的 GCC 用户社区,研究机构和学术界代表组成的组织。

academia [ˌækəˈdiːmiə]:n. 学术界,学术生涯
committee [kəˈmɪti]:n. 委员会
acronym [ˈækrənɪm]:n. 首字母缩略词

1.2 Major features of GCC (GCC 主要特征)

This section describes some of the most important features of GCC.
本节介绍一些 GCC 中的最重要的特性。

First of all, GCC is a portable compiler – it runs on most platforms available today, and can produce output for many types of processors. In addition to the processors used in personal computers, it also supports microcontrollers, DSPs and 64-bit CPUs.
首先,GCC 是一个可移植的编译器 – 它能在今天绝大部分平台上运行,能为许多类型的 CPU 提供输出。除了在个人计算机方面用到的处理器外,它也支持微控制器、DSP 和 64 位 CPU。

GCC is not only a native compiler – it can also cross-compile any program, producing executable files for a different system from the one used by GCC itself. This allows software to be compiled for embedded systems which are not capable of running a compiler. GCC is written in C with a strong focus on portability, and can compile itself, so it can be adapted to new systems easily.
GCC 不仅仅是个本地编译器 – 它还能够跨平台编译程序,即为不同于 GCC 本身所运行的系统生成可执行文件。这就可以为不能运行编译器的嵌入式系统编译软件。GCC 是用非常专注于可移植性的 C 语言写成的,它能对自身进行编译,所以它很容易被移植到新系统上。

GCC has multiple language frontends, for parsing different languages. Programs in each language can be compiled, or cross-compiled, for any architecture. For example, an ADA program can be compiled for a microcontroller, or a C program for a supercomputer.
GCC 有多种语言前端,用于解析不同的语言。对不同 CPU 架构不同语言的程序都能编译或跨平台编译。例如为微控制器编译 ADA 程序,或者为超级计算机编译 C 程序。

GCC has a modular design, allowing support for new languages and architectures to be added. Adding a new language front-end to GCC enables the use of that language on any architecture, provided that the necessary run-time facilities (such as libraries) are available. Similarly, adding support for a new architecture makes it available to all languages.
GCC 是按模块化设计的,可以加入对新语言和新 CPU 架构的支持。给 GCC 加入新语言的前端就能使在新的架构上使用该语言,只要提供必需的运行期环境 (比如库)。类似的,加入新架构的支持也使得所有语言同样支持该架构。

Finally, and most importantly, GCC is free software, distributed under the GNU General Public License (GNU GPL).[1] This means you have the freedom to use and to modify GCC, as with all GNU software. If you need support for a new type of CPU, a new language, or a new feature you can add it yourself, or hire someone to enhance GCC for you. You can hire someone to fix a bug if it is important for your work.
最后,也是最重要的,GCC 是自由软件,在 GNU General Public License (GNU GPL) 保护下发行。这意味着你享有使用和修改 GCC 的自由,就像其他所有 GNU 软件一样。如果你需要支持一种新的 CPU,一种新语言,或一种新的特性,你可以自己添加它,或雇人来为你增强 GCC。如果 GCC 对你的工作很重要,你也可以雇人修补 bug。

Furthermore, you have the freedom to share any enhancements you make to GCC. As a result of this freedom you can also make use of enhancements to GCC developed by others. The many features offered by GCC today show how this freedom to cooperate works to benefit you, and everyone else who uses GCC.
此外,你有分享你增强的 GCC 功能的自由。这种自由的结果是你也能够利用因其它人开发而对 GCC 增强的功能。今天 GCC 提供的许多特性显示了这种自由是怎样使得协作以利于你和使用 GCC 的每一个人的

1.3 Programming in C and C++ (C 和 C++ 编程)

C and C++ are languages that allow direct access to the computer’s memory. Historically, they have been used for writing low-level systems software, and applications where high-performance or control over resource usage are critical. However, great care is required to ensure that memory is accessed correctly, to avoid corrupting other data-structures. This book describes techniques that will help in detecting potential errors during compilation, but the risk in using languages like C or C++ can never be eliminated.
C 和 C++ 是两种允许直接访问计算机的内存的语言。历史上,它们被用于编写底层的系统软件和高性能的或控制资源很关键的应用程序。然而,需要特别当心以确保内存的正确访问,避免破坏其他数据结构。本书介绍的技巧有助于你在编译期间检测出潜在的错误,当然这种风险在使用像 C 或 C++ 这类语言时是不可避免的。

In addition to C and C++ the GNU Project also provides other high-level languages, such as GNU Common Lisp (gcl), GNU Smalltalk (gst), the GNU Scheme extension language (guile) and the GNU Compiler for Java (gcj). These languages do not allow the user to access memory directly, eliminating the possibility of memory access errors. They are a safer alternative to C and C++ for many applications.
除了 C 和 C++,GNU 项目还提供了其他高级语言,比如像 GNU Common Lisp (gcl)、GNU Smalltalk (gst)、GNU Scheme 扩展语言 (guile) 和 GNU 的 Java 编译器 (gcj)。这些语言不允许用户直接访问内存,避免了内存访问错误的可能性。对许多应用程序而言,它们是一种比 C 和 C++ 安全的选择。

1.4 Conventions used in this manual (本手册的排版约定)

This manual contains many examples which can be typed at the keyboard. A command entered at the terminal is shown like this,
本书包含许多你可以通过键盘输入的例子。在终端上键入的命令像下面那样显示:

yongqiang@deepnorth-amax:~$ command

followed by its output. For example:
跟着的是输出。例如:

yongqiang@deepnorth-amax:~$ echo "hello world"
hello world
yongqiang@deepnorth-amax:~$

The first character on the line is the terminal prompt, and should not be typed. The dollar sign $ is used as the standard prompt in this manual, although some systems may use a different character.
命令行上的第一个字符是终端提示符,不应当输入。美元符号 $ 在本书中是标准提示符,而一些系统可能用其他符号。

When a command in an example is too long to fit in a single line it is wrapped and then indented on subsequent lines, like this:
如果例子中一行太长而不能放入单独一行上,则会折行并在下一行缩进,像这样:

$ echo "an example of a line which is too long to fit 
    in this manual"

When entered at the keyboard, the entire command should be typed on a single line.
当在键盘上输入时,整行命令应当在一行上输入。

The example source files used in this manual can be downloaded from the publisher’s website,[2] or entered by hand using any text editor, such as the standard GNU editor, emacs. The example compilation commands use gcc and g++ as the names of the GNU C and C++ compilers, and cc to refer to other compilers. The example programs should work with any version of GCC. Any command-line options which are only available in recent versions of GCC are noted in the text.
本书中用到的例子源代码文件可以从出版方的网站下载,或者用任何文本编辑器手工输入,比如像标准的 GNU 编辑器 emacs。例子的编译命令用的是 GNU C 和 C++ 的编译器 gccg++,而 cc 指的是另外的编译器。例子程序应该可以在任何版本的 GCC 下编译。任何只有在最近的版本的 GCC 上才支持的命令行选项将在文中注明。

The examples assume the use of a GNU operating system – there may be minor differences in the output on other systems. Some non-essential and verbose system-dependent output messages (such as very long system paths) have been edited in the examples for brevity. The commands for setting environment variables use the syntax of the standard GNU shell (bash), and should work with any version of the Bourne shell.
例子假设使用的是 GNU 操作系统 – 其他系统上的输出可能有稍许差异。例子中一些无关紧要的和冗长的与系统相关的输出信息 (比如非常长的系统路径) 会被删减。设置环境变量的命令用的是标准 GNU shell (bash) 的语法,在任何版本的 Bourne shell 上应该也能工作。

References

http://lampwww.epfl.ch/~fsalvi/docs/gcc/www.network-theory.co.uk/docs/gccintro/index.html
https://www.linuxtopia.org/online_books/an_introduction_to_gcc/index.html
https://github.com/l10n-tw/An-Introduction-to-GCC-zh_TW

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yongqiang Cheng

梦想不是浮躁,而是沉淀和积累。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值