[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: what is the difference between shared and static libraries

.Let me explain the difference (as asked umpteen times)

1. Collection of one or more object files containing precompiled code
2. Named with a ".a" extension
3. Code in static libraries is linked in to the program at compile time

4. Becuase it is linked at compiled time the final executable size is much
5. The advantage is that you dont have to go hunting around for dependencies,
your executable is an independent unit
6.  for any change in library your code has to be recompiled

Creating a static lib
suppose your code is libramesh.c ..do the following

gcc -c libramesh.c -o libramesh.o
ar rcs libramesh.a libramesh.o

use nm libramesh.a to list the members of your libraray

1. Collection of object files containing precompiled code
2. Name ".so.x" where x is a veriosn
3. code in shared library is linked to program at run time
4. Because it is linked at run time they offer lesser space
5. They requiree fewer resources
6. Use lesser system memory
7. Disadvantage is you have to satisfy all the shared library dependencies..a
8. maintanence is easy

Creating a shared lib
gcc -fPIC -g -c libramesh.c -o libramesh.o
gcc -g -shared -Wl, -soname,libramesh.so -o libramesh.so.1.0 libramesh.o -lc

Make sure your library path exists in LD_LIBRARY_PATH before using it :)

Hope this explains it

Aravind S

"Ramesh.S" wrote:

> hi all,
> can anybody explain me the difference between the shared and static
> libraries.. both are going to be included before executoion..
> but even static libraries are also shared among rprograms know then why
> specifically two names are given.. i am not clear in this hting..
> also if i am writing a fucntion for converting a long value to  a string
> how to make is as a library... i heard that we can use
> ar archive.. but we have to compile it before or what.. if compiling means
> it should contain main().. then how can other program cna use that
> library..
> can anybody explain me from scratch.. i am very much interested in having
> my own libraries.. help me..
> ramesh
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
> ---------------------------------------------
> Find out more about this and other Linux India
> mailing lists at http://lists.linux-india.org/

Living on Earth is expensive, but it does include a free trip
round the sun