Sunday, July 22, 2012

Creating Static Libraries


Step1:-create the source files( .c files)

#vim main.c

#vim add.c

#vim sub.c

#vim multi.c

#vim div.c 

 

Step2:-create a relocatable files to the corresponding source files

#gcc -c main.c -o main.o

#gcc -c add.c -o add.o

#gcc -c sub.c -o sub.o

#gcc -c multi.c -o multi.o

#gcc -c div.c -o div.o

 

Step3:-By using a archiver tool("ar")to create static libraries

#gcc rcs libstatic.a add.o sub.o multi.o div.o

A static library must start with the three letters 'lib' and have the suffix '.a'

 

Step4:- Linking static library

#gcc -static main.c libstatic.a -o main 

 

Step5:-finally run the executable

#./main

No comments:

Post a Comment