GNU Compiler Collection - August 2005


Published on

GNU Compiler Collection - August 2005

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

GNU Compiler Collection - August 2005

  1. 1. GCC(GNU Compiler Collection) Tool Kit Linux Users Group, JMIAn overview of GNU Compiler Collection and its use for compiling C, C++ By: Saleem A. Ansari
  2. 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. 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. 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. 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. 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. 7. The famous C program/*hello.c*/#include<stdio.h>int main(){ printf(“Hello GCCn”); return 0;}Compilation:cc ­c hello.ccc ­o hello hello.o./hello
  8. 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.cppc++ ­o hello hello.o./hello
  9. 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. 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. 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. 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. 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. 14. MAKE indeed is a boonMAKEFILE--------------------------------------------------------------------------CC=gccCFLAGS=-Wall -gall: mystring.a testtest: mystring.a $(CC) $(CFLAGS) -c mystringtest.c $(CC) $(CFLAGS) -o test mystringtest.o mystring.aclean: rm -f test mystringtest.o mystring.o mystring.amystring.a: mystring.o ar cvr mystring.a mystring.o ranlib mystring.amystring.o: $(CC) $(CFLAGS) -c mystring.c
  15. 15. Compiling a complete software MPlayer as an example demonstration
  16. 16. For further information Manpages of gcc, make, gdb, nm, obj- dump, objcopy... Info pages of binutils
  17. 17. Thats all for now! Thanx