Download Microcross i.MX GNU X-Tools

Transcript
Section 4. How to Use i.MX GNU X-Tools
Now the loader searches the library after processing ‘first.c’ and is able to resolve any references requiring this
library.
When compiling a C program, you often don’t need to list any libraries explicitly on the command line. The GCC
automatically searches the system call library, I/O library, and run-time initialization routines. If you use any math
routines, you’ll need to search for the math library (‘-lm’); if you’re compiling C++ code, you need to include the C++
libraries (‘-lstdc++’).
4.7 Compilation Options
The following sections discuss other important options that are available with the GCC. There are many, many
other options – perhaps several hundred all-together – that control various details of compilation and optimization.
The chances are that you will never need these, but it won’t hurt to familiarize yourself with the complete
documentation for GCC. Complete coverage of GCC options is provided in Using and Porting GNU CC [reference
20].
4.7.1 Displaying compiler behavior
The ‘–v’ (verbose) option prints the compiler’s version number and complete details about how each pass is
executed. This option is particularly useful for finding out exactly which options your program is being linked with.
4.7.2 C Language Options
We’ll start by listing a few options for controlling the warning messages that GCC produces. There are many
options for controlling warnings; it’s possible to request (or inhibit) many warning messages on a per-message
basis. We’re not sure that’s really useful; we’ll limit ourselves to a few options that control large group of
messages:
-w
Suppress all warning messages.
-W
Produce some additional warning messages about legal (but questionable) coding practices.
-Wall
Produce even more warning messages about questionable coding practices.
-Wtraditional
Produce warning messages about code that is legal in both the ‘Kernighan and Ritchie’ and ANSI definitions of the
C language, but behaves differently in each case.
-Werror
Make all warnings into errors; that is, don’t attempt to produce an object file if a warning has occurred.
Now, we’ll discuss how to control various features of the C and C++ languages. There are basically three options
to worry about: ‘-traditional’, ‘-ansi’, and ‘-pedantic’. In most cases, it’s fairly easy to tell which you want. Older C
code – code that pedants the standard – should be compiled with ‘–traditional’. Newer code that has been written
to conform to the ANSI standard should be compiled with ‘–ansi’. Either option can accept prototypes, where you
specify the arguments on the same line as the function name, as in ‘func (char *arg)’.
i.MX GNU X-Tools User Guide ■ 51