CREATION OF STATIC LIBRARY
--------------------------------------------
The creation of static library is illustrated below with the help of different stages.
step1:
--------
vi file1.c /* The file to be called */
#include
void call()
{
printf("hai");
}
--> gcc -c file1.c
In this step,the object file of the code is obtained.
step 2:
--------
/*Header file which has prototype of file1.c*/
vi h1.h
void call();
--> ar rs libstat.a file1.o
The above command enables the object file generated in the previous stage
to be placed in the archiver.
step3:
-------
/*create "include" and "lib" folder(\home\student) */
note: create these folders in \home\student folder.
(a):copy h1.h file to include folder
(b):copy libstat.a to lib folder
step 4:
--------
vi program.c
#include
void main()
{
call();
return 0;
}
This is the application program making use of the static library.
step 5:
--------
gcc --static -I /home/student/include -L /home/student/lib -o program program.c -lstat
note -I stands for include and -L for lib and l for linking
Compiling the application code must be done using the above command
step 6:
-------
./program
Executing the application code
No comments:
Post a Comment