Post-Installation Tasks Installing GNU Compiler
3.3.1 Simple Compilation
Consider the following C source code file, which is named hello.c. We shall frequently refer to this program in this as well as coming chapters. include stdio.h main { printfHello world\n; } To compile this file, you just need to run the following command. [rrconformix 4] gcc hello.c [rrconformix 4] By default, this command will generate an output file named a.out, which can be exe- cuted on the command line as follows: [rrconformix 4] .a.out Hello world [rrconformix 4] Note that regardless of the name of your source code file, the name of the output file is always a.out. You may actually know what an ordinary a.out file is, but this isnt one of them. It is an elf file, despite its name. If you want to create an output file with a different name, you have to use the – o command line option. The following command creates an output file with name hello. gcc hello.c -o hello As you may have noted, the above commands do both the compiling and linking processes in a single step. If you don’t want to link the program, then simple compilation of hello.c file can be done with the following command. The output file will be hello.o and will contain object code. gcc –c hello.c Note that both – c and –o command line switches can be used simultaneously. The follow- ing command compiles hello.c and produces an output file test.o which is not yet linked. gcc –c hello.c -o test.o Usually when you compile many files in a project, you don’t create a.out files. Either you compile many files into object files and then link them together into an application or make executables with the same name as the source code file. 60 Chapter 3 • Compilers and Assemblers3.3.2 Default File Types
GCC can recognize an input file by the last part of its name, sometimes called an exten- sion. Table 3-1 shows file types and the extensions used with them. Depending upon a particular extension, gcc takes appropriate action to build the output file. Table 3-1 File types used with GCC File Extension File Type .c C source code file. .cc C++ source code file. .cp C++ source code file. .cxx C++ source code file. .cpp C++ source code file. .c+ C++ source code file. .C C++ source code file. .m Objective C source code file. .F Fortran source code file. .fpp Fortran source code file. .FPP Fortran source code file. .h C header file. .i C source code file. GCC does not preprocess it. .ii C++ source code file. GCC does not preprocess it. .mi Objective C source code file. GCC does not preprocess it. .f Fortran source code file. GCC does not preprocess it. .for Fortran source code file. GCC does not preprocess it. .FOR Fortran source code file. GCC does not preprocess it. .s Assembler code. GCC does not preprocess it. .S Assembler file. Compiling a Program 61 This means that if you use command gcc hello.c, GCC will consider hello.c as a C program and will invoke appropriate helper programs to build the output. However, if you use gcc hello.cpp command, GCC will consider hello.cpp as a C++ program and will compile it accordingly. You can also select a language type with a particular file using – x com- mand line option. Table 3-2 lists languages that can be selected with this option. Note that – x option applies to all the files that follow until you turn it off using the –x none option on the command line. This is especially important when you use the GNU make utility discussed in Chapter 5. By default, the object file created by GCC has .o extension, replacing the original exten- sion of the file. You can create output file with a particular name using – o command line option. The following command creates test.o file from hello.c. gcc –c hello.c –o test.o3.3.3 Compiling to Intermediate Levels
The compilation process involves many steps like preprocessing, assembling and linking. By default GCC carries out all of these processes and generates executable code as you have seen earlier. However, you can force GCC not to do all of these steps. For example, using the – c command line option, the gcc command will only compile a source code file and will not gen- erate executable object code. As you already know, the following command compiles file hello.c and creates an object file hello.o. gcc –c hello.c If you look at the type of the newly created object file using the file command, you can see that this is not a linked file. This is shown in the following command output. [rootconformix chap-03] file hello.o hello.o: ELF 32-bit LSB relocatable, Intel 80386, version 1, not stripped [rootconformix chap-03] Table 3-2 Selecting languages with –x option. Option Language -x c lowercase c C language selection -x c++ C++ file -x objective-c Objective C -x assembler Assembler file -x f77 Fortran file -x java Java language fileParts
» the linux development platform 2003
» Requirement Gathering Life Cycle of a Software Development Project
» Writing Functional Specifications Life Cycle of a Software Development Project
» Creating Architecture and Design Documents
» Implementation and Coding Life Cycle of a Software Development Project
» Testing Life Cycle of a Software Development Project
» Technical documentation developed during the development process. This includes
» Technical documentation prepared for technical support staff. This includes technical
» End-user manuals and guides. This is the documentation for the end user to assist the
» Software Releases Support and New Features
» Hardware Platform Components of a Development System
» Operating System Components of a Development System
» Editors Components of a Development System
» Compilers and Assemblers Components of a Development System
» Debuggers Components of a Development System
» Version Control Systems Components of a Development System
» Selection Criteria for Hardware Platform Selection Criteria for Software Development Tools
» Creating Deadlines Managing Development Process
» Managing the Development Team
» Resolving Dependencies Managing Development Process
» Libraries Linux Development Platform Specifications LDPS and Linux
» Open Source Developers Network at http:www.osdn.org
» Extensibility What to Look for in an Editor
» References and Resources the linux development platform 2003
» Target machine. This is the machine for which the newly built compiler will generate
» Post-Installation Tasks Installing GNU Compiler
» Compiling to Intermediate Levels
» Compilation with Debug Support
» Compilation with Optimization Compiling a Program
» Compiling Source Code for Other Languages
» Linking a program Assembling a Program
» Creating Libraries the linux development platform 2003
» Standard Libraries the linux development platform 2003
» Compiling Fortran Programs the linux development platform 2003
» Smalltalk Oberon Other Compilers
» The target 2. Dependencies Basic Terminology
» The explicit rules 2. The implicit rules
» Input Files Introduction to GNU make
» Typical Contents of a Makefile
» Running make Introduction to GNU make
» Shell to Execute Commands Include Files
» The ftp server The The dnsresolver
» FTPOBJS OBJS Another Example of Makefile
» Explicit Rules The make Rules
» Implicit Rules The make Rules
» Defining Variables Types of Variables
» Pre-Defined Variables Automatic Variables
» Makefile in The Top Directory
» Makefile in common-dir Directory
» Makefile in the ftp-dir Directory
» Makefile in the tftp-dir Directory Makefile in the dns-dir Directory
» Building Everything Working with Multiple Makefiles and Directories
» The ifdef Directive Control Structures and Directives
» The ifndef Directive Control Structures and Directives
» Compilation Getting the Latest Version and Installation
» Most Commonly Used gdb Commands
» Passing Command Line Arguments to the Program Being Debugged
» The step and finish Commands
» Introduction to GDB Working with the Stack
» Displaying Program Variables Displaying Variables
» Automatic Displaying Variables with Each Command
» Displaying Environment Variables Displaying Variables
» Modifying Variables Displaying Variables
» Disabling Break Points Enabling Break Points
» Debugging Optimized Code the linux development platform 2003
» Debugging Running Processes the linux development platform 2003
» The kdbg Debugger Other Open Source Debuggers
» The ddd Debugger Other Open Source Debuggers
» The xxgdb Debugger Other Open Source Debuggers
» CVS Policies the linux development platform 2003
» Project Management and Communication
» Remote Repositories Checking out a Project
» Finding the Status of a Project
» Finding Differences Using the CVS Client
» Resolving Conflicts Using the CVS Client
» Checking the Project Back In Adding Files to a Project
» Removing Files from a Project
» Tags and Releases Using the CVS Client
» System Requirements Introduction to jCVS
» Installation Instructions Introduction to jCVS
» Using jCVS Introduction to jCVS
» Installing pcl-cvs Using Emacs with CVS
» Using pcl-cvs Using Emacs with CVS
» Have a shell account on the CVS server. 2. Create a publicprivate key pair on the client.
» Selecting Coding Styles Using indent Utility
» Formatting Braces Using indent Utility
» Formatting Declarations Using indent Utility
» Breaking Long Lines Using indent Utility
» Summary of Options Using indent Utility
» Using sed Utility Using cscope and cbrowser
» Generating C Function Prototypes from C Source Code Using cproto
» Using ltrace and strace Utilities
» Value 2. Type Name Using the nm Utility
» Using the ranlib Utility Using the strip Utility
» Using the strings Utility Using the addr2line Utility
» Host Machine Introduction to the Cross-Platform Development Process
» Target Machine Introduction to the Cross-Platform Development Process
» Cross Platform Development Cycle
» Embedded Systems and Moving Parts
» Embedded Systems and Power Consumption
» Embedded Operating Systems What are Embedded Systems?
» Knowledge of Target System Hardware
» Software Emulators Cross Compilations
» Using gdbserver with GNU Debugger
» Attaching to a Running Process Using gdbserver
» Arcom SBC-GX1 Board Hardware Used for Cross-Platform and Embedded Systems
» Artesyn PMPPC Mezzanine Card
» References the linux development platform 2003
» Java Compiler Java Virtual Machine
» Kaffe the linux development platform 2003
» The Jboss Java Development System
» Getting and Installing Java SDK from Sun Creating jar Files
» Creating Source Code File Compiling Java Code
» Running Java Applications Building Java Applications
» Using gcj to Build Java Applications
» Building Applets the linux development platform 2003
» Testing Applets with Netscape
» Jikes for Java the linux development platform 2003
Show more