The Compilation Process - PowerPoint PPT Presentation

johana
the compilation process l.
Skip this Video
Loading SlideShow in 5 Seconds..
The Compilation Process PowerPoint Presentation
Download Presentation
The Compilation Process

play fullscreen
1 / 6
Download Presentation
The Compilation Process
626 Views
Download Presentation

The Compilation Process

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. The Compilation Process .o 1110… Precompiler Assembler Compiler Linker .c .s .o Straight substitution of # signs 1010… 0110… .o 08048fac <main>: 8048fac: 55 push %ebp 8048fad: 89 e5 mov %esp,%ebp 8048faf: 83 ec 1c sub $0x1c,%esp 8048fb2: 57 push %edi 8048fb3: 56 push %esi 8048fb4: 53 push %ebx 8048fb5: 8b 75 08 mov 0x8(%ebp),%esi 8048fb8: 8b 5d 0c mov 0xc(%ebp),%ebx 8048fbb: c7 45 f8 00 00 00 00 movl $0x0,0xfffffff8(%ebp) 8048fc2: c7 45 f4 01 00 00 00 movl $0x1,0xfffffff4(%ebp) 8048fc9: 83 c4 f8 add $0xfffffff8,%esp 8048fcc: 68 7c 8e 04 08 push $0x8048e7c 8048fd1: 6a 0b push $0xb 8048fd3: e8 00 f7 ff ff call 80486d8 <_init+0x70> 8048fd8: 83 c4 f8 add $0xfffffff8,%esp 8048fdb: 68 4c 8e 04 08 push $0x8048e4c 1010… 1110… 0110… Final Executable Binary File

  2. Making Code More Modular Precompile info #include <stdlib.h> #include <stdio.h> #define MAX_WORD_LEN 30 void print_menu (void); int insert (char **array, int *numwords, char *buf); int print_to_file (char **array, int numwords, char *file); int main (int argc, char *argv[]) { ... } void print_menu (void) { ... } int insert (char **array, int *numwords, char *buf) { ... } Create a header file for each Prototypes Main Function Leave in main .c file Place each in its own .c file Additional Functions

  3. Making Code More Modular labx.c print.h #include <stdlib.h> #include <stdio.h> #include “print.h” #include “insert.h” #define MAX_WORD_LEN 30 int main (int argc, char *argv[]) { ... } void print_menu (void); int print_to_file (char **array, int numwords, char *file); insert.h void print_menu (void) { ... } int print_to_file (char **array, int numwords, char *file); { ... } int insert (char **array, int *numwords, char *buf); print.c insert.c int insert (char **array, int *numwords, char *buf) { ... }

  4. Putting the Modules Together labx.c labx.o print.c print.o LINKER insert.o insert.c a.out

  5. Confused??? Enter Makefiles • Located in the directory of your code • Must be named Makefile • Syntax: • Comments:#Put anything here • Macros:CC = gccCFLAGS = -Wall –O –pedantic –o LabX.exe • FILES = labx.c print.c insert.c ---------------------------------------------$(CC) $(CFLAGS) $(FILES) Translates to gcc –Wall –O2 –pedantic –o LabX.exe labx.c print.c insert.c

  6. Syntax con’t. • Statements: {name}: {dependency1 dependency2 …} <tab> {command1} <tab> {command2} <tab> … • all: is the default statement (run when just ‘make’ is typed at the command line) • cleanup: cleans up when there is an error • make <name> will explicitly run the statement name