SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
GCC(GNU Compiler Collection)
         Tool Kit



         Linux Users Group, JMI

An overview of GNU Compiler Collection and
         its use for compiling C, C++

           By: Saleem A. Ansari
The Free Software Compiler
          An Introduction to GCC
   Virtually all other open software is based on it at
    some level or another. Even other languages,
    such as Perl and Python, are written in C, which
    is compiled by the GNU compiler.
   This piece of software is more fundamental to
    the entire free software movement than any
    other. In fact, without it or something like it,
    there would be no free software movement. Lin-
    ux is possible because of GCC.
GCC is a product of the GNU
                  Project.
   The fundamental language of GCC is C. The en-
    tire compiler system began as a C compiler and,
    over time, the other languages were added to it.
   C++ Was the First Addition. Now can compile
    C++, Objective-C, Java, Ada, Fortran ...
   The GCC set of compilers runs on many plat-
    forms. We can do multi-platform compilation us-
    ing the same machine. (Alpha, HPPA, Intel x86,
    MIPS, PowerPC, Sparc)
GCC Components
   cc1: The actual C compiler.
   cc : A version of gcc that sets the default lan-
    guage to C and automatically includes the
    standard C libraries when linking.
   cc1plus : The actual C++ compiler.
   g++ / c++ : A version of gcc that sets the default
    language to C++.
   jc1: The actual Java compiler.
   gcj The driver program used to compile Java.
   gcc: The driver program.
GCC Components contd.
   as : The GNU assembler. It is really a family of
    assemblers because it can be compiled to work
    with one of several different platforms. This pro-
    gram is part of the binutils package.
   gdb : The GNU debugger, which can be used to
    examine the values and actions inside a pro-
    gram while it is running.
   Other tools : gprof (profiler), ld(linker),
    ar(archive), make, nm, objcopy, objdump, ranlib,
    strip ...
Developing Software using GCC

   You need a text editor: gedit, kedit, vi
    emacs, joe, nedit etc.
   You need to learn atleast one of the lan-
    guages supported by GCC: C, C++, Java,
    Fortran etc.
   You need the GCC Toolkit Installed on the
    system itself
   get-set-go...
The famous C program
/*hello.c*/
#include<stdio.h>
int main()
{
     printf(“Hello GCCn”);
     return 0;
}

Compilation:
cc ­c hello.c
cc ­o hello hello.o
./hello
The famous program in C++
/*hello.cpp*/
#include<iostream>
using namespace std;
int main(void)
{
      cout << “Hello GCC” << endl;
      return 0;
}

Compilation:
c++ ­c hello.cpp
c++ ­o hello hello.o
./hello
Command Line Options
   -c compile and produce object
    code
   -o name of translated code file
   -l specify library
   -I specify include directory
   -Wall show all errors
   -std=__ assume the specified
    standard
   -v give verbose output
   -s, -S result in assembly code
    production
   -O1, O2, -O3 Optimization Levels
Yet another simple example. Illegal
         memory access!!
 #include<stdio.h>
 int main()
 {
 char *str=”abc”;
 str[0]=’d’;
 str[1]=’e’;
 str[2]=’f’;
 puts(str);
 return 0;
 }
Here comes the debugger

   Use the GCC command line switch -g or
    -ggdb to incorporate debugging information
    into the object code
   Invoke the gdb and fire!!
Multiple Files: A simple example

/*mystring.c*/
#include<string.h>               /*mystring.h*/
int palindrome(char s[])         int palindrome(char s[]);
{
      int l=strlen(s)-1;
      int i=0;
      while(i<l)
            if(s[i++]!=s[l--])
                   return 0;
      return 1;
}
/*mystringtest.c*/
                        continued...
#include<stdio.h>
#include "mystring.h"
int main()
{
      char str[50];
      puts("Enter a string:");
      gets(str);
      if(palindrome(str))
             printf("Its a palindrome");
      else
             printf("Its not a palindrome");
      return 0;
}
MAKE indeed is a boon
MAKEFILE
--------------------------------------------------------------------------
CC=gcc
CFLAGS=-Wall -g
all: mystring.a test
test: mystring.a
        $(CC) $(CFLAGS) -c mystringtest.c
        $(CC) $(CFLAGS) -o test mystringtest.o mystring.a
clean:
        rm -f test mystringtest.o mystring.o mystring.a
mystring.a: mystring.o
        ar cvr mystring.a mystring.o
        ranlib mystring.a
mystring.o:
        $(CC) $(CFLAGS) -c mystring.c
Compiling a complete software




 MPlayer as an example demonstration
For further information

   Manpages of gcc, make, gdb, nm, obj-
    dump, objcopy...
   Info pages of binutils
Thats all for now!




      Thanx

Contenu connexe

Tendances

GEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions FrameworkGEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions Framework
Alexey Smirnov
 
Debugging With GNU Debugger GDB
Debugging With GNU Debugger GDBDebugging With GNU Debugger GDB
Debugging With GNU Debugger GDB
kyaw thiha
 
Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...
Yandex
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
Alpana Gupta
 
Claire protorpc
Claire protorpcClaire protorpc
Claire protorpc
Fan Robbin
 
Turbo C Compiler Reports
Turbo C Compiler Reports Turbo C Compiler Reports
Turbo C Compiler Reports
Sunil Kumar R
 
Gdb tutorial-handout
Gdb tutorial-handoutGdb tutorial-handout
Gdb tutorial-handout
Suraj Kumar
 

Tendances (20)

GCC compiler
GCC compilerGCC compiler
GCC 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)
 
introduction of c langauge(I unit)
introduction of c langauge(I unit)introduction of c langauge(I unit)
introduction of c langauge(I unit)
 
C compilation process
C compilation processC compilation process
C compilation process
 
GEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions FrameworkGEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions Framework
 
Debugging Applications with GNU Debugger
Debugging Applications with GNU DebuggerDebugging Applications with GNU Debugger
Debugging Applications with GNU Debugger
 
Debugging With GNU Debugger GDB
Debugging With GNU Debugger GDBDebugging With GNU Debugger GDB
Debugging With GNU Debugger GDB
 
C++ compilation process
C++ compilation processC++ compilation process
C++ compilation process
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...
Разработка кросс-платформенного кода между iPhone &lt; -> Windows с помощью o...
 
Gnu debugger
Gnu debuggerGnu debugger
Gnu debugger
 
GCC RTL and Machine Description
GCC RTL and Machine DescriptionGCC RTL and Machine Description
GCC RTL and Machine Description
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Advanced Debugging with GDB
Advanced Debugging with GDBAdvanced Debugging with GDB
Advanced Debugging with GDB
 
LLVM Compiler - Link Time Optimization
LLVM Compiler - Link Time OptimizationLLVM Compiler - Link Time Optimization
LLVM Compiler - Link Time Optimization
 
Claire protorpc
Claire protorpcClaire protorpc
Claire protorpc
 
Turbo C Compiler Reports
Turbo C Compiler Reports Turbo C Compiler Reports
Turbo C Compiler Reports
 
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
 
Gdb tutorial-handout
Gdb tutorial-handoutGdb tutorial-handout
Gdb tutorial-handout
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
 

En vedette

Principles of compiler design
Principles of compiler designPrinciples of compiler design
Principles of compiler design
Janani Parthiban
 

En vedette (8)

HRM - PM in GCC
HRM - PM in GCCHRM - PM in GCC
HRM - PM in GCC
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
 
Gcc opt
Gcc optGcc opt
Gcc opt
 
MinGw Compiler
MinGw CompilerMinGw Compiler
MinGw Compiler
 
Principles of compiler design
Principles of compiler designPrinciples of compiler design
Principles of compiler design
 
NetBeans para Java, C, C++
NetBeans para Java, C, C++NetBeans para Java, C, C++
NetBeans para Java, C, C++
 
Deep C
Deep CDeep C
Deep C
 
GCC
GCCGCC
GCC
 

Similaire à GNU Compiler Collection - August 2005

20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
eugeniadean34240
 

Similaire à GNU Compiler Collection - August 2005 (20)

C introduction by piyushkumar
C introduction by piyushkumarC introduction by piyushkumar
C introduction by piyushkumar
 
1 c introduction
1 c introduction1 c introduction
1 c introduction
 
gcc and friends
gcc and friendsgcc and friends
gcc and friends
 
ICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdfICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdf
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 
lab1-ppt.pdf
lab1-ppt.pdflab1-ppt.pdf
lab1-ppt.pdf
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
 
GCC
GCCGCC
GCC
 
Hidden Dragons of CGO
Hidden Dragons of CGOHidden Dragons of CGO
Hidden Dragons of CGO
 
Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and Golang
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
 
C
CC
C
 
C
CC
C
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
 
Golang execution modes
Golang execution modesGolang execution modes
Golang execution modes
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).doc
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
 

Plus de Saleem Ansari (10)

Web Application Development
Web Application DevelopmentWeb Application Development
Web Application Development
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Lessons I learnt from Linux Asia 2006
Lessons I learnt from Linux Asia 2006Lessons I learnt from Linux Asia 2006
Lessons I learnt from Linux Asia 2006
 
Linx Asia 2006 Experience
Linx Asia 2006 ExperienceLinx Asia 2006 Experience
Linx Asia 2006 Experience
 
Introduction to Qt Designer
Introduction to Qt DesignerIntroduction to Qt Designer
Introduction to Qt Designer
 
Linux Asia 2006
Linux Asia 2006Linux Asia 2006
Linux Asia 2006
 
Introduction to Free and Open Source Software - August 2005
Introduction to Free and Open Source Software - August 2005Introduction to Free and Open Source Software - August 2005
Introduction to Free and Open Source Software - August 2005
 
JMILUG Introduction - 2007
JMILUG Introduction - 2007JMILUG Introduction - 2007
JMILUG Introduction - 2007
 
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
 
Fedora Embedded at foss.in 2010
Fedora Embedded at foss.in 2010Fedora Embedded at foss.in 2010
Fedora Embedded at foss.in 2010
 

Dernier

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

GNU Compiler Collection - August 2005

  • 1. GCC(GNU Compiler Collection) Tool Kit Linux Users Group, JMI An overview of GNU Compiler Collection and its use for compiling C, C++ By: Saleem A. Ansari
  • 2. The Free Software Compiler An Introduction to GCC  Virtually all other open software is based on it at some level or another. Even other languages, such as Perl and Python, are written in C, which is compiled by the GNU compiler.  This piece of software is more fundamental to the entire free software movement than any other. In fact, without it or something like it, there would be no free software movement. Lin- ux is possible because of GCC.
  • 3. GCC is a product of the GNU Project.  The fundamental language of GCC is C. The en- tire compiler system began as a C compiler and, over time, the other languages were added to it.  C++ Was the First Addition. Now can compile C++, Objective-C, Java, Ada, Fortran ...  The GCC set of compilers runs on many plat- forms. We can do multi-platform compilation us- ing the same machine. (Alpha, HPPA, Intel x86, MIPS, PowerPC, Sparc)
  • 4. GCC Components  cc1: The actual C compiler.  cc : A version of gcc that sets the default lan- guage to C and automatically includes the standard C libraries when linking.  cc1plus : The actual C++ compiler.  g++ / c++ : A version of gcc that sets the default language to C++.  jc1: The actual Java compiler.  gcj The driver program used to compile Java.  gcc: The driver program.
  • 5. GCC Components contd.  as : The GNU assembler. It is really a family of assemblers because it can be compiled to work with one of several different platforms. This pro- gram is part of the binutils package.  gdb : The GNU debugger, which can be used to examine the values and actions inside a pro- gram while it is running.  Other tools : gprof (profiler), ld(linker), ar(archive), make, nm, objcopy, objdump, ranlib, strip ...
  • 6. Developing Software using GCC  You need a text editor: gedit, kedit, vi emacs, joe, nedit etc.  You need to learn atleast one of the lan- guages supported by GCC: C, C++, Java, Fortran etc.  You need the GCC Toolkit Installed on the system itself  get-set-go...
  • 7. The famous C program /*hello.c*/ #include<stdio.h> int main() { printf(“Hello GCCn”); return 0; } Compilation: cc ­c hello.c cc ­o hello hello.o ./hello
  • 8. The famous program in C++ /*hello.cpp*/ #include<iostream> using namespace std; int main(void) { cout << “Hello GCC” << endl; return 0; } Compilation: c++ ­c hello.cpp c++ ­o hello hello.o ./hello
  • 9. Command Line Options  -c compile and produce object code  -o name of translated code file  -l specify library  -I specify include directory  -Wall show all errors  -std=__ assume the specified standard  -v give verbose output  -s, -S result in assembly code production  -O1, O2, -O3 Optimization Levels
  • 10. Yet another simple example. Illegal memory access!! #include<stdio.h> int main() { char *str=”abc”; str[0]=’d’; str[1]=’e’; str[2]=’f’; puts(str); return 0; }
  • 11. Here comes the debugger  Use the GCC command line switch -g or -ggdb to incorporate debugging information into the object code  Invoke the gdb and fire!!
  • 12. Multiple Files: A simple example /*mystring.c*/ #include<string.h> /*mystring.h*/ int palindrome(char s[]) int palindrome(char s[]); { int l=strlen(s)-1; int i=0; while(i<l) if(s[i++]!=s[l--]) return 0; return 1; }
  • 13. /*mystringtest.c*/ continued... #include<stdio.h> #include "mystring.h" int main() { char str[50]; puts("Enter a string:"); gets(str); if(palindrome(str)) printf("Its a palindrome"); else printf("Its not a palindrome"); return 0; }
  • 14. MAKE indeed is a boon MAKEFILE -------------------------------------------------------------------------- CC=gcc CFLAGS=-Wall -g all: mystring.a test test: mystring.a $(CC) $(CFLAGS) -c mystringtest.c $(CC) $(CFLAGS) -o test mystringtest.o mystring.a clean: rm -f test mystringtest.o mystring.o mystring.a mystring.a: mystring.o ar cvr mystring.a mystring.o ranlib mystring.a mystring.o: $(CC) $(CFLAGS) -c mystring.c
  • 15. Compiling a complete software MPlayer as an example demonstration
  • 16. For further information  Manpages of gcc, make, gdb, nm, obj- dump, objcopy...  Info pages of binutils
  • 17. Thats all for now! Thanx