SlideShare une entreprise Scribd logo
1  sur  9
Compilation Process in C
R RAJ KUMAR

2/4/2014

RAJ KUMAR RAMPELLI
Compilation process in C
• Compilation process ?
– Constructing an executable image for an application
– FOUR stages
– Command:
gcc <options> <source_file.c>

• Compiler Tool
– gcc
• man gcc (on Linux m/c)

2/4/2014

RAJ KUMAR RAMPELLI
4 stages of compilation process
Preprocessor
gcc –E app.c –o app.i
app.c  Hello.c
Compiler
gcc –S app.i –o app.s

Assembler
gcc –c app.s –o app.o

Linker
gcc app.o –o app

Output  Executable (a.out)
Run  ./app (Loader)
2/4/2014

RAJ KUMAR RAMPELLI
4 stages of compilation process
• Preprocessor
– Expansion of Header files
– Substitute macros and inline functions

• Compiler
– Generates assembly language
– Verification of functions usage using prototypes
– Header files: Prototypes declaration

• Assembler
– Generates re-locatable object file (contains m/c
instructions)
– nm app.o
0000000000000000 T main
U puts
– Nm or objDump tool used to view object files
2/4/2014

RAJ KUMAR RAMPELLI
4 stages of compilation proces
(contd..)
• Linker
– Generates executable file (nm tool used to view exe file)
– Binds appropriate libraries
• Static Linking
• Dynamic Linking (default)
Timing of linking
At Load time
At Run time

• Loader
–
–
–
–

2/4/2014

Evaluate size of code and data segment
Allocates address space in the user mode and transfers them into memory
Load dependent libraries needed by program and links them
Invokes Process Manager  Program registration

RAJ KUMAR RAMPELLI
Compiling a C Program
• gcc <options> program_name.c
Options:
-----------Wall: Shows all warnings
-o output_file_name: By default a.out executable
file is created when we compile our program with
gcc. Instead, we can specify the output file name
using "-o" option.
-g: Include debugging information in the binary.

2/4/2014

RAJ KUMAR RAMPELLI
Linking Multiple files to make
executable file
• If we have two programs say prog1.c and prog2.c for one single task then
we can make single executable file using following instructions
First, compile these two files with option "-c"
gcc -c prog1.c
gcc -c prog2.c
-c: Tells gcc to compile and assemble the code, but not link.
We get two files as output, prog1.o and prog2.o
Now, we can link these object files into single executable file using below
instruction.
gcc -o prog prog1.o prog2.o

Now, the output is prog executable file.
We can run our program using
./prog
2/4/2014

RAJ KUMAR RAMPELLI
Linking with other libraries
• Normally, compiler will read/link libraries from /usr/lib directory to
our program during compilation process.
But, there are some case where we need to link our programs with
libraries like pthreads and realtime libraries (rt library).
Use below instruction for this purpose
gcc <options> program_name.c -lpthread -lrt

-lpthread: Link with pthread library
-lrt: Link with rt library
Option here is "-l<library>"
Another option "-L <dir>" used to tell gcc compiler search for
libraries in given <dir> directory.

2/4/2014

RAJ KUMAR RAMPELLI
Thank You

2/4/2014

RAJ KUMAR RAMPELLI

Contenu connexe

Tendances (20)

Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
OOP - Benefits and advantages of OOP
OOP - Benefits and advantages of OOPOOP - Benefits and advantages of OOP
OOP - Benefits and advantages of OOP
 
Types of Compilers
Types of CompilersTypes of Compilers
Types of Compilers
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 
Debuggers in system software
Debuggers in system softwareDebuggers in system software
Debuggers in system software
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
Package in Java
Package in JavaPackage in Java
Package in Java
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 
Compilation of c
Compilation of cCompilation of c
Compilation of c
 
P code
P codeP code
P code
 
structured programming
structured programmingstructured programming
structured programming
 
compiler vs interpreter
compiler vs interpretercompiler vs interpreter
compiler vs interpreter
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Assemblies
AssembliesAssemblies
Assemblies
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreter
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 

En vedette

NetBeans para Java, C, C++
NetBeans para Java, C, C++NetBeans para Java, C, C++
NetBeans para Java, C, C++Manuel Antonio
 
Principles of compiler design
Principles of compiler designPrinciples of compiler design
Principles of compiler designJanani Parthiban
 
Compiling Under Linux
Compiling Under LinuxCompiling Under Linux
Compiling Under LinuxPierreMASURE
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1Dave Cross
 
GCC Compiler as a Performance Testing tool for C programs
GCC Compiler as a Performance Testing tool for C programsGCC Compiler as a Performance Testing tool for C programs
GCC Compiler as a Performance Testing tool for C programsDaniel Ilunga
 
GEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions FrameworkGEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions FrameworkAlexey Smirnov
 
GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005Saleem Ansari
 
How it's made: C++ compilers (GCC)
How it's made: C++ compilers (GCC)How it's made: C++ compilers (GCC)
How it's made: C++ compilers (GCC)Sławomir Zborowski
 

En vedette (16)

NetBeans para Java, C, C++
NetBeans para Java, C, C++NetBeans para Java, C, C++
NetBeans para Java, C, C++
 
Principles of compiler design
Principles of compiler designPrinciples of compiler design
Principles of compiler design
 
HRM - PM in GCC
HRM - PM in GCCHRM - PM in GCC
HRM - PM in GCC
 
G++ & GCC
G++ & GCCG++ & GCC
G++ & GCC
 
Gccgdb
GccgdbGccgdb
Gccgdb
 
Gcc opt
Gcc optGcc opt
Gcc opt
 
Compiling Under Linux
Compiling Under LinuxCompiling Under Linux
Compiling Under Linux
 
GCC, GNU compiler collection
GCC, GNU compiler collectionGCC, GNU compiler collection
GCC, GNU compiler collection
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
 
GCC Compiler as a Performance Testing tool for C programs
GCC Compiler as a Performance Testing tool for C programsGCC Compiler as a Performance Testing tool for C programs
GCC Compiler as a Performance Testing tool for C programs
 
GEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions FrameworkGEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions Framework
 
GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005GNU Compiler Collection - August 2005
GNU Compiler Collection - August 2005
 
MinGw Compiler
MinGw CompilerMinGw Compiler
MinGw Compiler
 
How it's made: C++ compilers (GCC)
How it's made: C++ compilers (GCC)How it's made: C++ compilers (GCC)
How it's made: C++ compilers (GCC)
 
Deep C
Deep CDeep C
Deep C
 
GCC
GCCGCC
GCC
 

Similaire à C compilation process

Autotools pratical training
Autotools pratical trainingAutotools pratical training
Autotools pratical trainingThierry Gayet
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Ahmed El-Arabawy
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projectsMpho Mphego
 
Process (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oSProcess (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oSHarrytoye2
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using SwiftDiego Freniche Brito
 
From gcc to the autotools
From gcc to the autotoolsFrom gcc to the autotools
From gcc to the autotoolsThierry Gayet
 
Programming in c_in_7_days
Programming in c_in_7_daysProgramming in c_in_7_days
Programming in c_in_7_daysAnkit Dubey
 
C Programming Compilation Process.pdf
C Programming Compilation Process.pdfC Programming Compilation Process.pdf
C Programming Compilation Process.pdfAhmedAbdElGhafar17
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxCoolGamer16
 
Machine Understandable code
Machine Understandable codeMachine Understandable code
Machine Understandable codejanusathis
 
Composer & Drupal
Composer & DrupalComposer & Drupal
Composer & Drupaldrubb
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfThninh2
 
Efficient development workflows with composer
Efficient development workflows with composerEfficient development workflows with composer
Efficient development workflows with composernuppla
 

Similaire à C compilation process (20)

Autotools pratical training
Autotools pratical trainingAutotools pratical training
Autotools pratical training
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projects
 
Process (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oSProcess (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oS
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
Comparing C and Go
Comparing C and GoComparing C and Go
Comparing C and Go
 
Composer namespacing
Composer namespacingComposer namespacing
Composer namespacing
 
From gcc to the autotools
From gcc to the autotoolsFrom gcc to the autotools
From gcc to the autotools
 
Programming in c_in_7_days
Programming in c_in_7_daysProgramming in c_in_7_days
Programming in c_in_7_days
 
Composer
ComposerComposer
Composer
 
GCC
GCCGCC
GCC
 
C Programming Compilation Process.pdf
C Programming Compilation Process.pdfC Programming Compilation Process.pdf
C Programming Compilation Process.pdf
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
 
Machine Understandable code
Machine Understandable codeMachine Understandable code
Machine Understandable code
 
Unit 2 l1
Unit 2 l1Unit 2 l1
Unit 2 l1
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
Autotools
AutotoolsAutotools
Autotools
 
Composer & Drupal
Composer & DrupalComposer & Drupal
Composer & Drupal
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdf
 
Efficient development workflows with composer
Efficient development workflows with composerEfficient development workflows with composer
Efficient development workflows with composer
 

Plus de RajKumar Rampelli

Writing Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxWriting Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxRajKumar Rampelli
 
Introduction to Python - Running Notes
Introduction to Python - Running NotesIntroduction to Python - Running Notes
Introduction to Python - Running NotesRajKumar Rampelli
 
Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewRajKumar Rampelli
 
Learn python - for beginners - part-2
Learn python - for beginners - part-2Learn python - for beginners - part-2
Learn python - for beginners - part-2RajKumar Rampelli
 
Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginnersRajKumar Rampelli
 
Introduction to Kernel and Device Drivers
Introduction to Kernel and Device DriversIntroduction to Kernel and Device Drivers
Introduction to Kernel and Device DriversRajKumar Rampelli
 
System Booting Process overview
System Booting Process overviewSystem Booting Process overview
System Booting Process overviewRajKumar Rampelli
 
Network security and cryptography
Network security and cryptographyNetwork security and cryptography
Network security and cryptographyRajKumar Rampelli
 
Tasklet vs work queues (Deferrable functions in linux)
Tasklet vs work queues (Deferrable functions in linux)Tasklet vs work queues (Deferrable functions in linux)
Tasklet vs work queues (Deferrable functions in linux)RajKumar Rampelli
 

Plus de RajKumar Rampelli (15)

Writing Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxWriting Character driver (loadable module) in linux
Writing Character driver (loadable module) in linux
 
Introduction to Python - Running Notes
Introduction to Python - Running NotesIntroduction to Python - Running Notes
Introduction to Python - Running Notes
 
Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver Overview
 
Learn python - for beginners - part-2
Learn python - for beginners - part-2Learn python - for beginners - part-2
Learn python - for beginners - part-2
 
Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginners
 
Linux watchdog timer
Linux watchdog timerLinux watchdog timer
Linux watchdog timer
 
Linux Kernel I/O Schedulers
Linux Kernel I/O SchedulersLinux Kernel I/O Schedulers
Linux Kernel I/O Schedulers
 
Linux GIT commands
Linux GIT commandsLinux GIT commands
Linux GIT commands
 
Introduction to Kernel and Device Drivers
Introduction to Kernel and Device DriversIntroduction to Kernel and Device Drivers
Introduction to Kernel and Device Drivers
 
System Booting Process overview
System Booting Process overviewSystem Booting Process overview
System Booting Process overview
 
Network security and cryptography
Network security and cryptographyNetwork security and cryptography
Network security and cryptography
 
Tasklet vs work queues (Deferrable functions in linux)
Tasklet vs work queues (Deferrable functions in linux)Tasklet vs work queues (Deferrable functions in linux)
Tasklet vs work queues (Deferrable functions in linux)
 
Sql injection attack
Sql injection attackSql injection attack
Sql injection attack
 
Turing awards seminar
Turing awards seminarTuring awards seminar
Turing awards seminar
 
Higher education importance
Higher education importanceHigher education importance
Higher education importance
 

Dernier

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 

Dernier (20)

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 

C compilation process

  • 1. Compilation Process in C R RAJ KUMAR 2/4/2014 RAJ KUMAR RAMPELLI
  • 2. Compilation process in C • Compilation process ? – Constructing an executable image for an application – FOUR stages – Command: gcc <options> <source_file.c> • Compiler Tool – gcc • man gcc (on Linux m/c) 2/4/2014 RAJ KUMAR RAMPELLI
  • 3. 4 stages of compilation process Preprocessor gcc –E app.c –o app.i app.c  Hello.c Compiler gcc –S app.i –o app.s Assembler gcc –c app.s –o app.o Linker gcc app.o –o app Output  Executable (a.out) Run  ./app (Loader) 2/4/2014 RAJ KUMAR RAMPELLI
  • 4. 4 stages of compilation process • Preprocessor – Expansion of Header files – Substitute macros and inline functions • Compiler – Generates assembly language – Verification of functions usage using prototypes – Header files: Prototypes declaration • Assembler – Generates re-locatable object file (contains m/c instructions) – nm app.o 0000000000000000 T main U puts – Nm or objDump tool used to view object files 2/4/2014 RAJ KUMAR RAMPELLI
  • 5. 4 stages of compilation proces (contd..) • Linker – Generates executable file (nm tool used to view exe file) – Binds appropriate libraries • Static Linking • Dynamic Linking (default) Timing of linking At Load time At Run time • Loader – – – – 2/4/2014 Evaluate size of code and data segment Allocates address space in the user mode and transfers them into memory Load dependent libraries needed by program and links them Invokes Process Manager  Program registration RAJ KUMAR RAMPELLI
  • 6. Compiling a C Program • gcc <options> program_name.c Options: -----------Wall: Shows all warnings -o output_file_name: By default a.out executable file is created when we compile our program with gcc. Instead, we can specify the output file name using "-o" option. -g: Include debugging information in the binary. 2/4/2014 RAJ KUMAR RAMPELLI
  • 7. Linking Multiple files to make executable file • If we have two programs say prog1.c and prog2.c for one single task then we can make single executable file using following instructions First, compile these two files with option "-c" gcc -c prog1.c gcc -c prog2.c -c: Tells gcc to compile and assemble the code, but not link. We get two files as output, prog1.o and prog2.o Now, we can link these object files into single executable file using below instruction. gcc -o prog prog1.o prog2.o Now, the output is prog executable file. We can run our program using ./prog 2/4/2014 RAJ KUMAR RAMPELLI
  • 8. Linking with other libraries • Normally, compiler will read/link libraries from /usr/lib directory to our program during compilation process. But, there are some case where we need to link our programs with libraries like pthreads and realtime libraries (rt library). Use below instruction for this purpose gcc <options> program_name.c -lpthread -lrt -lpthread: Link with pthread library -lrt: Link with rt library Option here is "-l<library>" Another option "-L <dir>" used to tell gcc compiler search for libraries in given <dir> directory. 2/4/2014 RAJ KUMAR RAMPELLI

Notes de l'éditeur

  1. Library: Set of reusable functions
  2. nm Hello0000000000600e40 d _DYNAMIC0000000000600fe8 d _GLOBAL_OFFSET_TABLE_0000000000400628 R _IO_stdin_used w _Jv_RegisterClasses0000000000600e20 d __CTOR_END__0000000000600e18 d __CTOR_LIST__0000000000600e30 D __DTOR_END__0000000000600e28 d __DTOR_LIST__00000000004006d8 r __FRAME_END__0000000000600e38 d __JCR_END__0000000000600e38 d __JCR_LIST__0000000000601020 A __bss_start0000000000601010 D __data_start00000000004005e0 t __do_global_ctors_aux0000000000400490 t __do_global_dtors_aux0000000000601018 D __dso_handle w __gmon_start__0000000000600e14 d __init_array_end0000000000600e14 d __init_array_start0000000000400540 T __libc_csu_fini0000000000400550 T __libc_csu_init U __libc_start_main@@GLIBC_2.2.50000000000601020 A _edata0000000000601030 A _end0000000000400618 T _fini00000000004003f0 T _init0000000000400440 T _start000000000040046c t call_gmon_start0000000000601020 b completed.73820000000000601010 W data_start0000000000601028 b dtor_idx.73840000000000400500 t frame_dummy0000000000400524 T main U puts@@GLIBC_2.2.5