1 / 13

C Development Environment

C Development Environment. Life Cycle of a C program Development. Designing [ Your Brain™ ] Editing [ xemacs , vi ?! ] Compiling [ gcc ] Code Checking [ lint, smash ] Testing / Debugging [ gdb , gof printf ] Purifying [ e-fence, valgrind , purify ]

lilah
Download Presentation

C Development Environment

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C Development Environment

  2. Life Cycle of a C program Development Designing [Your Brain™] Editing [xemacs , vi ?!] Compiling [gcc] Code Checking [lint, smash] Testing / Debugging [gdb , gof printf] Purifying [e-fence, valgrind , purify] Profiling & Optimizing [gcov , gprof] Packaging [deb , rpm]

  3. Compiling with GCC #include <stdio.h> int main ( ) { printf (“hi\n”); } hw GCC -o hw hw.c Executable File Source code File hw.c Let’s get it done the simplest way first

  4. Compiling with GCC in one step hw.c hw gcc -o hw hw.c Source File Executable File [tux:~/hw]: GCC -o hw hw.c [tux:~/hw]: ls -l hw -rwxr-xr-x 1 gaspara voicedb 13877 Aug 8 15:05 hw [tux:~/hw]: ./hw hi [tux:~/hw]: file hw hw: ELF 32-bit LSB executable, Intel 80386, version 1, dynamically linked (uses shared libs), not stripped [tux:~/hw]: more /usr/share/magic

  5. Compiling with GCC in two steps hw.c hw.o gcc -c hw.c Object File Source File hw gcc -o hw hw.o Executable File [tux:~/hw]: GCC -c hw.c [tux:~/hw]: ls -l hw.o [tux:~/hw]: file hw.o [tux:~/hw]: GCC -o hw2 hw.o [tux:~/hw]: ls -l hw hw2 [tux:~/hw]: file hw2

  6. What’s behind GCC ? hw.c hw.i cpp0 Preprocessor Expanded Source File Source File Compiler hw.s ccl asm File Other User .o Files Assembler hw.o as obj File Link Editor / Linker /usr/lib Libraries hw ld collect2 Exec File

  7. More Informations about GCC ? hw.i Expanded Source File Different Types of Files’ Extensions are detailed in man gcc Similarly, options to stop GCC at any step of the source code processing chain are available -c Stops after hw.o -S Stops after hw.s -E Stops after hw.i hw.s Asm File hw.o Obj File hw Exec File

  8. Precompiling hw.i Contents of /usr/include/stdio.h Expanded Source File #include <stdio.h> int main ( ) { printf (“hi\n”); } int main ( ) { printf (“hi\n”); } hw.s Asm File hw.o Source code File hw.c Expanded Source File hw.i Obj File hw cpp GCC -E hw.c Exec File

  9. Compiling hw.i (…) main: pushl %ebp movl %esp, %ebp subl $8, %esp subl $12, %esp pushl $.LC0 call printf addl $16, %esp (…) Contents of /usr/include/stdio.h Expanded Source File hw.s int main ( ) { printf (“hi\n”); } Asm File hw.o Expanded Source File hw.i Asm Source File hw.s Obj File hw ccl GCC -S hw.c Exec File

  10. Assembling hw.i (…) main: pushl %ebp movl %esp, %ebp subl $8, %esp subl $12, %esp pushl $.LC0 call printf addl $16, %esp (…) Expanded Source File hw.o hw.s Obj File GCC -c hw.c Asm File as Asm Source File hw.s hw.o Relocatable Object File = assembled asm code (architecture dependent) = ELF32_i386 format (linux) Ready for link w/ other obj to form an executable file Obj File hw Exec File

  11. Linking hw.i hw Expanded Source File hw.o Exec File Obj File hw.s ld Asm File hw.o GCC -o hw hw.c Gathering altogether Your Object Files Object Files from libraries The C runtime code Obj File hw Exec File

  12. Linking hw.i hw hw.o ld Expanded Source File Exec File Obj File A taste of what linking is really about… (edited) ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o hw /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i386-redhat-linux/2.96/crtbegin.o -L/usr/lib/gcc-lib/i386-redhat-linux/2.96 -L/usr/lib/ hw.o -lgcc -lc -lgcc /usr/lib/gcc-lib/i386-redhat-linux/2.96/crtend.o /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crtn.o hw.s Asm File hw.o Obj File hw Exec File

  13. Blank Slide…

More Related