Operating System - HP-UX
1834751 Members
2990 Online
110070 Solutions
New Discussion

Shared libraries- What are these used for?

 
SOLVED
Go to solution
SM_3
Super Advisor

Shared libraries- What are these used for?


What are shared libraries?

What are the used for?

Do we have to create these?

Can you give an example?

Thanks
6 REPLIES 6
Zeev Schultz
Honored Contributor
Solution

Re: Shared libraries- What are these used for?

Also called dynamically linked libraries.What is done during linking - mutual memory space is defined for all libraries.What if we need certain library to be loaded only during program start - thats what shared library used for. And another benefit is that such a library can be loaded during programm execution and by this shared between different processes that need it.

Excellent article on unix libraries:

http://www.linuxjournal.com/article.php?sid=6463
So computers don't think yet. At least not chess computers. - Seymour Cray
Hari Kumar
Trusted Contributor

Re: Shared libraries- What are these used for?

Please find Linkers and Libraries Guide by HP which had very good set of explanations under the Creating and Using Libraries chapter,
http://docs.hp.com/hpux/onlinedocs/B2355-90655/B2355-90655.html

U can also see more info at man pages of
chatr , ld , dld.sl for more info.

Thanks,
Information is Wealth ; Knowledge is Power
Tim Sanko
Trusted Contributor

Re: Shared libraries- What are these used for?

These are module that can be used by other programs. One example is the oracle libraries. They could be used by powerhouse,j2ee and other programs.

dld.sl is another example.

Where these shared module hide usually is in the SHLIB_PATH.

A typical SHLIB_PATH might be
$ORACLE_HOME/lib:$PH_USR/lib:/lib

You will not likely create these, unless you are a developer.

Tim
Tim Sanko
Trusted Contributor

Re: Shared libraries- What are these used for?

I am having a problem with the ssssss key.

I can spell but the key ssssssssstick..

Tim
Umapathy S
Honored Contributor

Re: Shared libraries- What are these used for?

Shared libs as the name specifies, shared among many exectuables. Its loaded into memory only once and the exectuables link with it will have the whereabouts of the shared lib TEXT.

They are used to reduce the size of the executables, when changed they wont break the existing code unless it does by purpose. Each library has its version to be identified with.

Yes we have to create them specially. The code should be compiled as Position Independent Code . The following created PIC object file.
cc -Ae +z a.c -o a.o
cc -b -o liba.sl a.o
creates a shared library out of a.o
Arise Awake and Stop NOT till the goal is Reached!
RolandH
Honored Contributor

Re: Shared libraries- What are these used for?

A shared libary is simply a collection of functions, which are used in the main program ( why reinvent the whell ).

For example the most important libary on your hp-ux system is the libc.(/usr/lib/linc.2).

Shared libary vs. static labary
A shared libary is loaded at startup of a program. So it is "outside" the main program.
A big advantage of shared libaries are, they can be replaced if there is a newer one or because of a bug in the lib.

If your program use static libaries, then these libaries are "inside" the program.
A disadvantage is, if a libary must be replaced you must recompile the hole program. But somtime it is better to use static libs. ie for security reasons (/sbin/passwd).


an example for a dynamic and a static program on your hp-ux box is "ls".
Do an ldd on
/sbin/ls
/usr/bin/ls

see what happens !!

HTH
Roland

Sometimes you lose and sometimes the others win