• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
GNU Compiler Collection - August 2005
 

GNU Compiler Collection - August 2005

on

  • 560 views

GNU Compiler Collection - August 2005

GNU Compiler Collection - August 2005

Statistics

Views

Total Views
560
Views on SlideShare
560
Embed Views
0

Actions

Likes
0
Downloads
5
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    GNU Compiler Collection - August 2005 GNU Compiler Collection - August 2005 Presentation Transcript

    • 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
    • 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.ccc ­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.cppc++ ­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 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
    • 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