Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HP-UX : shl_load & related functions

Posted on 1998-11-25
5
Medium Priority
?
634 Views
Last Modified: 2013-12-26
If anybody could explain the advantages of using explicit
run time dynamic linking in HP-UX programs(using shl_load or
dlopen functions) over implicit linking using linker options
e.g in GCC compiler i am using following options.
gcc -c -fPIC -shared -export-dynamic -o <lib.so>
then linking it with any other program using the functions &
data defined in <lib.so>
Please tell me any code sample if possible to show proper use of shl_load or related functions.

With Best Regards,
Flower
0
Comment
Question by:flower020397
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:seedy
ID: 1294460
The same advantages that a 'LoadLibrary' and 'GetProcAddress' provide under Windows.
Lets assume we are building a product under windows that interfaces to one ore more mail services, like MAPI, VIM or SMTP.
Lets also assume that you do this depending on user's choice.  Normally, these service APIs are in seperate DLLs (MAPI32.DLL or WINSOCK.DLL, etc).

If you code does explicit LoadLibrary, and then GetProcAddress to get function pointer and call the fucniton via the pointer.  In this case, when the product is installed on a users' machine, it will interface with only the mail interface that machine provides.  For example, if the user does not have MAPI32.DLL or VIM.DLL, but has only WINSOCK, you program will still work fine.

On the other hand, if you have "implicitly linked" the DLLs than, the product will not run, if any of these DLLs are not found.  (Lets' say, VIM.DLL is not available).

The same will hold good for HP-UX.  Replace "shl_load" for 'LoadLibray' and 'shl_findsym' for 'GetProcAddress'.
But the dynamic/shared libraries (or the linker) on most UNIX have few additional feature than on the Windows.  For example, you can use -B option of HP-UX linker to specify run-time binding behavior of a program using shared libraries.  For more info man "ld".
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 600 total points
ID: 1294461
> On the other hand, if you have "implicitly linked" the DLLs than, the product will not run, if any of  these DLLs are not found.
NO, this depends on the linker options: -B defered  or  -B immediate  or  -B nonfatal

> But the dynamic/shared libraries (or the linker) on most UNIX have few additional feature than  on the Windows.
I would state the other way around, see comment about -B option  ;-))

----------------------
The advantage using implicit linking is that there is only one precondition at runtime: the linked libs must exist (but see -B option also).
You don't need anything special in your code for this behavior.

While the advantage of using shl_load, dlopen etc. has the advantage that you can
load any kind of shared object dynamically from within your code. You don't need to have the libs (and its functions) at compile- and runtime.
0
 
LVL 2

Expert Comment

by:seedy
ID: 1294462
ahoffmann:
>On the other hand, if you have "implicitly linked" the DLLs than, the product will not run, if any of these DLLs are not found.

I was still talking about Windows.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1294463
aha, so it's time to tell us the "Windows features" ;-)
0
 
LVL 2

Expert Comment

by:seedy
ID: 1294464
ahoffmann:
>On the other hand, if you have "implicitly linked" the DLLs than, the product will not run, if any of these DLLs are not found.

I was still talking about Windows.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Loops Section Overview

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question