Presentation is loading. Please wait.

Presentation is loading. Please wait.

COP 3515 IT Program DesignAlessio Gaspar … 1 C Development Environment.

Similar presentations


Presentation on theme: "COP 3515 IT Program DesignAlessio Gaspar … 1 C Development Environment."— Presentation transcript:

1 COP 3515 IT Program DesignAlessio Gaspar … 1 C Development Environment

2 COP 3515 IT Program DesignAlessio Gaspar … 2 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] Life Cycle of a C program Development

3 COP 3515 IT Program DesignAlessio Gaspar … 3 Compiling with GCC GCC -o hw hw.c Let’s get it done the simplest way first #include int main ( ) { printf (“hi\n”); } #include int main ( ) { printf (“hi\n”); } Source code File hw.c hw Executable File

4 COP 3515 IT Program DesignAlessio Gaspar … 4 Compiling with GCC in one step gcc -o hw hw.c Source File hw 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]: 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 hw.c [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 [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 COP 3515 IT Program DesignAlessio Gaspar … 5 Compiling with GCC in two steps gcc -c hw.c Source File hw.o Object 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 [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 hw.c hw Executable File gcc -o hw hw.o

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

7 COP 3515 IT Program DesignAlessio Gaspar … 7 More Informations about GCC ? hw.i Expanded Source File hw.s Asm File hw.o Obj File hw Exec 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 -cStops after hw.o -SStops after hw.s -EStops after hw.i 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 -cStops after hw.o -SStops after hw.s -EStops after hw.i

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

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

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

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

12 COP 3515 IT Program DesignAlessio Gaspar … 12 Linking hw.i Expanded Source File hw.s Asm File hw.o Obj File hw Exec File ld hw.o 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 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 Exec File

13 COP 3515 IT Program DesignAlessio Gaspar … 13 Blank Slide…


Download ppt "COP 3515 IT Program DesignAlessio Gaspar … 1 C Development Environment."

Similar presentations


Ads by Google