What are tools for?
• Creating code modules
compiler
• Creating program from modules
linker
• Compiling groups of programs (dependencies)
• Debugging code
tracer, debugger, code checker
• Profiling and optimization
Tool Chain
• GCC
• Binutils
• Liberary
• Other tools:make,cvs,gdb
GCC
• The GNU Compiler Collection (GCC) is the most important piece of open source software in the world.
• Virtually all other open software is based on it at some level or another.
• Even other languages, such as Perl and Python, are written in C, which is compiled by the GNU compiler.
• GNU Compiler Collection(也就是所谓的GCC)是由高级语言源码来构建二进制文件的编译器以及实用程序的集合。
• GCC不仅是GNU/Linux上的标准编译器,而且他也是嵌入式系统开发的标准编译器。
• GCC支持各种不同的目标架构
为我们编译所用的平台构建软件
交叉编译(为一个不同的目标构建)
GCC提供了40种不同的结构体系:其中包括X86,RS6000,Arm,PowerPC以及其他的许多
• GCC也可以用在40多种不同的主机系统
Linux
Solaris
Windows
GCC supported languages
• C
Is the Fundamental Language
• C++
Was the First Addition
• Objective-C
Objective-C It is referred to as “C with objects”
• Fortran
• Java
• Ada
The newest addition to the GCC family is Ada. It was added as a fully functional compiler originally developed separately by Ada Core Technologies as the GNAT Ada 95 compiler,and donated to GCC in October of 2001.
GCC platforms


• The reason for primary and secondary testing on such a limited number of platforms is a matter of manpower. If your platform is not represented here, you may still find that the compiler runs perfectly on your system.
GCC Execution

GCC parts list – most important parts
• GCC is made up of many components. parts of GCC,not all of them are always present. Some of them are language specific, so if a particular language has not been installed, certain files will be missing from that system.
• Gcc: The driver program that coordinates execution of compilers and linkers to produce the desired output.
• Cc1: The actual C compiler.
• crt0.o: The initialization and shutdown code is customized for each system
• Libgcc: They are special routines that are linked with an executable program to perform fundamental tasks such as floating point arithmetic. The routines in this library are often platform dependent.
GCC parts list – others
• c++/g++: A version of gcc that sets the default language to C++ and automatically includes the standard C++ libraries when linking. This is the same as g++.
• Cc1plus: The actual C++ compiler.
• Collect2: One systems that do not use the GNU linker.
• Configure:
• cygwin1.dll:
• F77: The driver program used to compile Fortran.
• F771: The actual Fortran compiler.
• Gcj:Jc1: libgcj : for java
• Gnat1: Gnatbind: Gnatlink: for ADA
• Libobjc: The runtime library necessary for all Objective-C programs.
• libstdc++ :The runtime library contains all the C++ classes and functionsdefined as part of the standard language.
GCC Option(开关)
• Gcc最基本的用法是∶gcc [options] [filenames]
其中options就是编译器所需要的参数(开关),filenames给出相关的文件名称。
• -c,只编译,不连接成为可执行文件,编译器只是由输入的.c等源代码文件生成.o为后缀的目标文件
• -o output_filename,确定输出文件的名称为output_filename,同时这个名称不能和源文件同名。如果不给出这个选项,gcc就给出预设的可执行文件a.out。
• -g,产生符号调试工具(GNU的gdb)所必要的符号信息,要想对源代码进行调试,我们就必须加入这个选项。
• -O,对程序进行优化编译、连接,采用这个选项,整个源代码会在编译、连接过程中进行优化处理,这样产生的可执行文件的执行效率可以提高,但是,编译、连接的速度就相应地要慢一些。
• -O2,比-O更好的优化编译、连接,当然整个编译、连接过程会更慢。
• -lname,在连接时,装载名字为“libname.a”的函数库,该函数库位于系统预设的目录或者由-L选项确定的目录下。例如,-lm表示连接名为“libm.a”的数学函数库。
• 整个源代码程序由两个文件testmain.c 和testsub.c组成,程序中使用了系统提供的数学库,同时希望给出的可执行文件为test,这时的编译命令可以是∶
gcc testmain.c testsub.c -lm -o test
Binutils -- most important parts
• As:
The GNU assembler. It is really a family of assemblers because it can be compiled to work with one of several different platforms.
• Ld:
The GNU linker. This program combines a collection of object files into an executable program.
• Objcopy:
Copies and translates an object file from one binary format to another. This program is part of the binutils package.
• Ar:
A program to maintain library archive files by adding, removing,and extracting files from the archive. The most common use for this utility is to create and manage object library archives used by the linker. This program is part of the binutils package.
Binutils -- others 1
• Gprof: reports the amount of time spent in each function,
• Gcov: A profiling tool used with gprof to determine where the greatest
amount of time is being spent during the execution of your program.
• Gdb: The GNU debugger, which can be used to examine the values and
actions inside a program while it is running.
• Nm: Lists the symbols defined in an object file. This program is part
of the binutils package
• Objdump: Displays several different kinds of information stored inside one
or more object file. This program is part of the binutils package.
Binutils -- others 2
• Ranlib: Creates and adds an index to an ar archive file. The index is the one used by ld to locate modules in the library.
• Readelf: Displays information from an ELF formatted object file.
• Size: Lists the names and sizes of each of the sections in an object file.
• Strings: Reads through a file of any type and extracts the character stringsfor display.
• Strip: Removes the symbol table, along with any other information required for debugging
• And more:Make, Addr2line, Autoconf, c++filt, libtools, vcg, windres