Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > D

dlsetlibpath(3C)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

dlsetlibpath() — set the dynamic search path used to locate shared libraries

SYNOPSIS

cc [flag]... file... -ldl [library]...

#include <dlfcn.h>

int dlsetlibpath(const char *libpath, int flags)

Multithread Usage

This routine is thread-safe. Calls to dlsetlibpath() affect all subsequent calls to dlopen(), dlopene(), and dlgetfileinfo(), on any thread.

DESCRIPTION

dlsetlibpath() is one of a family of routines that give the user direct access to the dynamic linking facilities (using the -ldl option on the compiler or ld command line). dlsetlibpath() sets the dynamic search path used by dlopen(), dlopene(), and dlgetfileinfo() to locate shared libraries.

libpath is the dynamic search path. It is a list of one or more path names separated by colons (:).

When searching for a library, the dynamic loader uses search paths in the following default order:

1.

The dynamic search path specified in a call to dlsetlibpath().

2.

The LD_LIBRARY_PATH environment variable.

3.

The SHLIB_PATH environment variable.

4.

The embedded path of the calling module (executable program or shared library) for libraries named in calls to dlopen(), dlopene(), or dlgetfileinfo(). For dependent libraries, the embedded path of the library that named it as a dependent is used.

5.

The standard library path.

6.

The current working directory. (This is only for libraries named in calls to dlopen(), dlopene(), and dlgetfileinfo(), not their dependent libraries.)

(See dld.so(5) for additional information on search paths and options that can change the order described above.)

Any combination of these paths may be disabled by setting flags to one or more of the following flag values OR'ed together. If the following value is set, the dynamic loader does not search the specified location:

RTLD_FLAG_DISABLE_DYNAMIC_PATH

Directories specified in the dynamic search path.

RTLD_FLAG_DISABLE_LD_LIBRARY_PATH

Directories specified in the LD_LIBRARY_PATH environment variable.

RTLD_FLAG_DISABLE_SHLIB_PATH

Directories specified in the SHLIB_PATH environment variable.

RTLD_FLAG_DISABLE_EMBEDDED_PATH

Directories specified in the embedded path.

RTLD_FLAG_DISABLE_STD_PATH

Standard library directory.

RTLD_FLAG_DISABLE_CWD_PATH

Current working directory.

Multiple search paths can be disabled by OR'ing individual flags:

flags = RTLD_FLAG_DISABLE_STD_PATH | RTLD_FLAG_DISABLE_CWD_PATH

A single search path can be enabled by setting flags to the complement of the flag value that disables that search path:

flags = ~RTLD_FLAG_DISABLE_DYNAMIC_PATH

EXAMPLES

The following example illustrates the use of dlsetlibpath() to set the dynamic search path and disable other search paths. For simplicity, error checking has been omitted.

#include <dlfcn.h> int main() { void *handle; int status; int flags; /* Set dynamic search path and disable the embedded * path and the standard library directory. */ flags = RTLD_FLAG_DISABLE_EMBEDDED_PATH | RTLD_FLAG_DISABLE_STD_PATH; status = dlsetlibpath("/opt/lib:/opt/usr/lib", flags); /* Call dlopen to load a library using the dynamic * search path. */ handle = dlopen("mylib.so", RTLD_LAZY); /* Remove the dynamic search path and reenable all * disabled search paths. */ status = dlsetlibpath(NULL, 0); }

RETURN VALUE

If successful, dlsetlibpath() returns 0, otherwise a non-0 value is returned. More detailed diagnostic information is available through dlerror() or dlerrno().

ERRORS

If dlsetlibpath() fails, a subsequent call to dlerrno() returns one of the following values:

RTLD_ERR_NO_MEMORY

Cannot allocate dynamic memory.

RTLD_ERR_CANT_APPLY_RELOC

Failed to apply relocation while resolving call to dlsetlibpath().

RTLD_ERR_SIGINHIBIT_FAILED

siginhibit call failed on entry to dlsetlibpath().

RTLD_ERR_SIGENABLE_FAILED

sigenable call failed on exit from dlsetlibpath().

RTLD_ERR_SETCANCELSTATE_FAILED

__thread_setcancelstate failed on entry to or exit from dlsetlibpath().

RTLD_ERR_INV_DLSETLIBPATH_ARGUMENT

Invalid argument in call to dlsetlibpath().

SEE ALSO

dlopen(3C), dlopene(3C), dlgetfileinfo(3C), dlerrno(3C), dlerror(3C), dld.so(5).

Texts and Tutorials:

HP-UX Linker and Libraries Online User Guide

(See the +help option)

HP-UX Linker and Libraries User's Guide

(See manuals(5) for ordering information)

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.