Re: Differences of file



I am not sure this is the right mailing list to talk about that but
here is the answer :

When you write a program in C, your file end with .c.
If you write in assembly, your file end with .S (or .s).
If you want to see the assembly code generate for a C program
you can do :

gcc -S my_pgm.c -o my_pgm.s

When you compile a program made of several files you
compile files seperately. You generate .o files. ex :

gcc -c file1.c -o file1.o
gcc -c file2.c -o file2.o

then link them to create your final program :

gcc file1.o file2.o -o file_to_exec

If you change only file2, you don't need to
do gcc -sc file1.c ....

Files .o are made of code that can be execute
by the processor but in your file, you call external
functions like those in file2.c. You can't exec file1.o because
file1.o need functions in file2.o to work.

.a and .so files are libraries. If you write some code used in
many project it can be good to seperate it.  Suppose you
have two files with only functions (no main), you can create
a library with those files :

gcc file1.c file2.c -o file.a

or 

gcc file1.c file2.c -o file.so

then use this function in another program like that 

gcc my_pgm.c -o my_pgm -lfile

If you create a .a file this mean that you want a static
library. In other word, after compilation my_pgm contain
function of file1 and file2, you no more file file.a.

If you create a .so file, this mean you want a dynamic library.
In other word, after compilation, your program says that it
need file.so and don't own function of file1 and file2. If you
want my_pgm to work, you need to place file.so in a directory
written in /etc/ld.so.conf or in the env variable LD_LIBRARY_PATH.
The avantage of this is that if you have many program loaded in
the system using those function (file1 and file2) they are only
present one time in the memory.

About .la files, I don't know what they are used for. It is
certainly for some configuration tools.

With .c file you make have .s file. With .s or .c file, you can
make .o file. With .o file, you can make .a file or .so file.
With .a file you can make .so file (not sure I have never done
that).

This is a short introduction with an horrible english but I hope
it help. I don't know any doc which explain this in detail but
you have to look after gcc doc I think.

Daniel Lacroix

> Hi Everybody
>              Can any one tell me the differences between .so .S .la
> .a .o etc files and how can i convert in other form in detail, or refer some 
> ssource where can i hit to dig all these stuff.
>                                            Munish




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]