GNU Tool Chain
GNU Tool Chain
GNU Tool Chain
What is GNU
• Advantages:
– Pretty up-to-date and reliable
– Available on variety of platforms
– Free and open source
– Can compile C, C++
– It’s both compiler and linker
– Eg: gcc main.c module1.c module2.c
–o program
GCC Cont…Command line
options
• syntax:
gcc options files
• Most common options to gcc are
-c, -o, -g, -Wall, -I, -L, -l
GCC : Simple Example
/* main.c */
#include<stdio.h>
int main()
{
printf("Hello world\n") ;
return 0 ;
}
#include<stdio.h> /* sub.c */
int sub(int a, int b)
{
printf("In the subtraction funtcion\n") ;
return (a-b) ;
}
#include<stdio.h> /* main.c */
#include "include.h"
int main()
{
int a = 5, b =4 ;
printf("Addition of these two numbers is %d\n", add(a,b)) ;
printf("Subtraction of these two numbers is %d\n",sub(a,b)) ;
return 0 ;
}
GCC – generation of a binary file
Method - I
gcc main.c add.c sub.c -o main
GCC – generation of a binary file
Method II
gcc -c main.c
gcc -c add.c
gcc -c sub.c
main.o: main.c
gcc -c main.c
add.o: add.c
gcc -c add.c
sub.o: sub.c
gcc -c sub.c
clean:
rm –rf *.o
# simple make file
all: main
main.o: main.c
gcc -c main.c
add.o: add.c
gcc -c add.c
sub.o: sub.c
gcc -c sub.c
clean:
rm –rf *.o
Makefile cont…
• Variable Definitions
– Variables are not pre-declared, you just set them
with '='
– Predefined: CC, CFLAGS(-I, -g), LDFLAGS (-l, -L)
– Eg:CC = gcc
CFLAGS = -g -I/usr/abc/xyz/include
# A part of make file with variables
CC = gcc
• Options: main: main.o add.o sub.o
-k ignore errors $(CC) -o main main.o sub.o add.o
-f <filename>
-n to print out what it would have done without actually
doing it.
GNU Debugger