Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Brian J. Gough, Richard M. Stallman

Rating No ratings yet

This manual provides a complete tutorial introduction to the GNU C and C++ compilers, gcc and g++. Many books teach the C and C++ languages, this book teaches you how to use the compiler itself. All the common problems and error messages encountered by new users of GCC are carefully explained, with numerous easy-to-follow ''Hello World'' examples. Topics covered include: compiling C and C++ programs using header files and libraries, warning options, use of the preprocessor, static and dynamic linking, debugging, optimization, platform-specific options, profiling and coverage testing, paths and environment variables, and the C++ standard library and templates. Features a special foreword by Richard M. Stallman, principal developer of GCC and founder of the GNU Project. All the money raised from the sale of this book will support the development of free software and documentation.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 This is the definitive practical guide to using the GCC and G++ compilers themselves—not the C/C++ languages—covering everything from your first `hello.c` to advanced optimization, debugging, and library management. Ideal for beginners who want to compile with confidence and experienced programmers migrating from other compilers. 【Book Arc】 - **Opening (~0%–10%)**: Introduces GCC's history, the GNU Project's free-software philosophy (with Stallman's foreword), and the compiler's major features. Sets the stage for a tool-focused, not language-focused, manual. - **Early (~10%–30%)**: Walks through compiling simple C programs, interpreting error/warning messages (`file:line:message` format), and the crucial distinction between errors and warnings. Covers multi-file projects, object files, linking order, and linking with external libraries like `libm.a`. - **Middle (~30%–50%)**: Dives into compilation options: setting include/link search paths via `-I`/`-L` and environment variables (`C_INCLUDE_PATH`, `LIBRARY_PATH`), understanding static vs. shared libraries (`.a` vs. `.so`), and managing runtime loading with `LD_LIBRARY_PATH`. Also covers C language standards (`-ansi`, `-pedantic`) and warning options in `-Wall`. - **Late (~50%–75%)**: Explores the preprocessor, debugging with `gdb`, and optimization flags. Explains how the compiler's internal stages (preprocessing, compilation, assembly, linking) affect your workflow and output. - **Ending (~75%–100%)**: Covers compiler-related tools: creating libraries with `ar`, profiling with `gprof`, and coverage testing with `gcov`. Concludes with a deep-dive into how the compiler works internally, plus C++ standard library and template specifics. 【Key Takeaways】 - **Warnings are your first line of defense** (Early): `-Wall` catches subtle bugs like mismatched `printf` format specifiers (`%f` for an integer) that would otherwise corrupt output. Always compile with warnings enabled—clean compilation means fewer runtime surprises. - **Link order matters for libraries** (Early): Place `-lm` (or any library) *after* the source/object files that use it. Libraries calling functions in other libraries must appear before them (e.g., `-lglpk -lm`). This left-to-right convention prevents "undefined reference" errors. - **Header files declare, source files define** (Early): Use `#include "file.h"` for local headers (searches current directory first) vs. `#include <file.h>` for system headers. Proper declarations prevent corrupted function arguments and undefined behavior. - **Search paths are configurable three ways** (Middle): Command-line `-I`/`-L` options, environment variables (`C_INCLUDE_PATH`, `LIBRARY_PATH`), and colon-separated lists. Precedence: command-line first, then environment, then system defaults—essential for managing non-standard installs. - **Shared libraries beat static for flexibility** (Middle): GCC prefers `.so` files over `.a` when both exist. Shared libraries allow updates without recompiling, but require `LD_LIBRARY_PATH` to be set for the runtime loader to find them. - **Standards compliance is a spectrum** (Middle): `-ansi` disables GNU extensions that conflict with ANSI/ISO; `-ansi -pedantic` rejects *all* extensions (e.g., variable-size arrays). Use these to write portable code, but know that "clean" doesn't guarantee standard-conformance. - **The compiler is a pipeline** (Late): Understanding the four stages—preprocessing, compilation, assembly, linking—helps you debug at the right level and use tools like `gprof` and `gcov` effectively. 【Reading Tips】 - **Skim the history and foreword** (~0%–10%): Stallman's foreword is inspiring but not technical. Skip ahead if you're already comfortable with compilers; the real value starts at "Compiling a C program." - **Deep-read the linking chapters** (~10%–30%): Link order and library resolution are the most common sources of beginner frustration. Work through the `calc.c` and `dbmain.c` examples carefully—they illustrate real-world pitfalls. - **Treat warning options as a checklist** (~30%–50%): Don't just read about `-Wall`; experiment with `-ansi`, `-pedantic`, and additional warnings on your own code. The examples show exactly what output to expect. - **Practice with environment variables** (~40%–50%): The `LD_LIBRARY_PATH` and `C_INCLUDE_PATH` sections are hands-on. Set them in a terminal session and verify the search order—this will save you hours debugging "No such file" errors. - **Use the tools chapter as a reference** (~75%–100%): `ar`, `gprof`, and `gcov` are best learned by doing. Skim the theory, then return when you need to profile or test coverage on a real project. 【Coverage Limits】 The excerpts cover roughly the first half of the book in detail (compilation, linking, search paths, standards). Later sections on the preprocessor, debugging, optimization, and C++ templates are mentioned in the table of contents but not fully represented in the sample—read the full book for those.
Page 3
. . . . . . . 9 2.4 Compiling files independently . . . . . . . . . . . . . . . . . . . . . . . . 10 2.4.1 Creating object files from source files . . . . ....
View in text
Page 11
ly, they have been used for writing low-level systems soft- ware, and applications where high-performance or control over resource usage are critical. Howeve...
View in text
Page 20
pporting both 64 and 32-bit executables the 64-bit versions of the libraries will often be stored in ‘/usr/lib64’ and ‘/lib64’, with the 32-bit versions in ‘...
View in text
Excerpt 4
typing, the LD_LIBRARY_PATH environment variable can be set once for each session in the appropriate login file, such as ‘.bash_profile’ for the GNU Bash she...
View in text
Excerpt 5
ocessor has made the substitution NUM 7→ 2+2 this is equiv- alent to compiling the following program: #include <stdio.h> int main (void) { printf("Value of N...
View in text
Excerpt 6
term sin(u/2): t = sin(u/2) x = cos(v)*(1+t) + sin(w)*(1-t) Chapter 6: Compiling with optimization 47 This function is small, so the overhead of calling it i...
View in text
Excerpt 7
u distribute executables using the C++ standard library you need to ensure that the recipient has a compatible version of ‘libstdc++’, or link your program s...
View in text
Excerpt 8
neral, inefficient). The IEEE standard specifies that these operations should produce special results to represent the quantities in the IEEE numeric format....
View in text
Tags
AI categories
ProgrammingC++C#
ISBN: 0954161793
Publisher: Network Theory Ltd.
Publish Year: 2004
Language: English
Pages: 124
File Format: PDF
File Size: 526.4 KB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…