01.09.2014 Views

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CH03.fm Page 63 Monday, October 7, 2002 8:33 PM<br />

Compiling a Program 63<br />

3.3.4 Compilation with Debug Support<br />

If you want to debug a program after compiling with gcc, you have to include debug<br />

information in the compiled program. <strong>The</strong> debug information is included in object file using the<br />

–g comm<strong>and</strong> line switch with gcc. <strong>The</strong> following comm<strong>and</strong> creates the hello.o file that contains<br />

debug information.<br />

[rr@conformix 4]$ gcc -g -c hello.c<br />

[rr@conformix 4]$<br />

Note that when you compile a program with debug information, the size may be quite<br />

large as compared to a file compiled without debug information. In the example program of<br />

hello.c, the size of hello.o is 908 bytes when compiled without debug information. <strong>The</strong><br />

size of hello.o is 10780 bytes when it is compiled with debug information.<br />

You can use multiple debug levels with –g option. <strong>The</strong> default debug level is 2 which is<br />

equivalent to using –g2 comm<strong>and</strong> line option. If you use –g3 comm<strong>and</strong> line option, information<br />

about macros is also included which makes it easier to debug macros.<br />

N O T E You can use the debug option with optimization<br />

options. Optimization options are discussed later in this chapter.<br />

With the –a option on the comm<strong>and</strong> line, you can also include some profiling information<br />

in the object code.<br />

You can also use some comm<strong>and</strong> line switches to provide extra information. For example,<br />

one useful thing is to print out a list of directories that the gcc comm<strong>and</strong> searches to find files.<br />

<strong>The</strong> following comm<strong>and</strong> will print all directories that gcc uses to search libraries, programs <strong>and</strong><br />

so on.<br />

[rr@conformix 4]$ gcc -print-search-dirs hello.c -o hello<br />

install: /usr/lib/gcc-lib/i386-redhat-linux/2.96/<br />

programs: =/usr/lib/gcc-lib/i386-redhat-linux/2.96/:/usr/lib/<br />

gcc-lib/i386-redhat-linux/2.96/:/usr/lib/gcc-lib/i386-redhat-<br />

linux/:/usr/lib/gcc/i386-redhat-linux/2.96/:/usr/lib/gcc/i386-<br />

redhat-linux/:/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../<br />

../../i386-redhat-linux/bin/i386-redhat-linux/2.96/:/usr/lib/<br />

gcc-lib/i386-redhat-linux/2.96/../../../../i386-redhat-linux/<br />

bin/<br />

libraries: =/usr/lib/gcc-lib/i386-redhat-linux/2.96/:/usr/lib/<br />

gcc/i386-redhat-linux/2.96/:/usr/lib/gcc-lib/i386-redhatlinux/2.96/../../../../i386-redhat-linux/lib/i386-redhatlinux/2.96/:/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../<br />

../i386-redhat-linux/lib/:/usr/lib/gcc-lib/i386-redhat-linux/<br />

2.96/../../../i386-redhat-linux/2.96/:/usr/lib/gcc-lib/i386-<br />

redhat-linux/2.96/../../../:/lib/i386-redhat-linux/2.96/:/lib/<br />

:/usr/lib/i386-redhat-linux/2.96/:/usr/lib/<br />

[rr@conformix 4]$

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!