Section 6.6. Dynamic Linking and Shared Libraries


6.6. Dynamic Linking and Shared Libraries

HP-UX applications that use dynamic linking functions such as shl_load, shl_finsym, and others need to be ported to use Linux dynamic link functions that begin with dl. HP-UX applications that already use the dl* functions need to be checked for proper API use because some dl functions that HP-UX supports are not supported on Linux.

Table 6-10 shows the HP-UX dl* function equivalents to HP-UX shl_* calls as well as other dl* calls present in HP-UX only.

Table 6-10. Dynamic Loading Library Functions Comparison Table

Routines

dl* Routines Present in HP-UX and Linux

Description

shl_load and cxxshl_load

dlopen HP-UX mode: RTLD_LAZY, RTLD_NOW, RTLD_GLOBAL, RTLD_LOCAL, RTLD_GROUP, RTLD_WORLD, RTLD_PARENT Linux flags: RTLD_LAZY, RTLD_NOW, RTLD_GLOBAL, RTLD_LOCAL, RTLD_NODELETE, RTLD_NOLOAD, RTLD_BINDING_MASK, RTLD_DEEPBIND

Loads a shared library.

shl_findsym

dlsym HP-UX handle: RTLD_DEFAULT, RTLD_NEXT, RTLD_SELF Linux handle: RTLD_DEFAULT, RTLD_NEXT

Finds the address of a global symbol in a shared library.

shd_get

dlget (HP-UX only)

Gets information about currently loaded library.

shl_gethandle

dlmodinfo (HP-UX only)

Gets descriptor information about a loaded shared library.

shl_definesym

No equivalent

Adds a new symbol to the global shared library symbol table.

shl_getsymbols

No equivalent

Returns a list of symbols in a shared library.

shl_unload

dlclose

Unloads the shared library.

None

dlerror

Returns a pointer to information about the last dlopen, dlsym, or dlclose error.

None

dladdr HP-UX DI_info structure: const char *dli_fname; void *dli_fbase; const char *dli_sname; void *dli_saddr; size_t dli_size; int dli_bind; int dli_type;

Translates address to symbolic information.

 

Linux DI_info structure: const char *dli_fname; void *dli_fbase; const char *dli_sname; void *dli_saddr; size_t dli_size;

 
 

dlgetname (HP-UX only)

Retrieves the name of a loaded module given a load model descriptor.


In Linux, a program that uses dynamic linking is linked with the libld.so library, -ldl. The libraries it loads do not need to be linked in during the build process. Chapter 3 contains example code that compiles on Linux using dl* routines.

6.6.1. GNU libtool

If portability is important to your program, you should consider using GNU libtool to build and install libraries. libtool masks the complexity of using shared libraries with a consistent, portable interface. For more information, visit www.gnu.org/software/libtool/libtool.html.




UNIX to Linux Porting. A Comprehensive Reference
UNIX to Linux Porting: A Comprehensive Reference
ISBN: 0131871099
EAN: 2147483647
Year: 2004
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net