Loading and initializing a module with the loadAndInit function

The loadAndInit function takes the same parameters and returns the same values and error codes as the load routine. See the load routine in the Technical Reference: Base Operating System and Extensions, Volumes 1 & 2 for more information.

Format

#include <load.h>
int (*loadAndInit(char *FilePath, unsigned int Flags, char *LibraryPath))();

Description

The loadAndInit function calls the AIX® load routine to load the specified module (shared library) into the calling process's address space. If the shared library is loaded successfully, any C++ initialization is performed. The loadAndInit function ensures that a shared library is only initialized once, even if dlopen is used to load the library too. Subsequent loads of the same shared library will not perform any initialization of the shared library.

If loading a shared library results in other shared libraries being loaded, the initialization for those shared libraries will also be performed (if it has not been previously). If loading a shared library results in the initialization of multiple shared libraries, the order of initialization is determined by the priority assigned to the shared libraries when they were built. Shared libraries with the same priority are initialized in random order.

To terminate and unload the shared library, use the terminateAndUnload function, described below.

Do not reference symbols in the C++ initialization that need to be resolved by a call to the AIX loadbind routine, since the loadbind routine normally is not called until after the loadAndInit function returns.

Parameters

FilePath
Points to the name of the shared library being loaded, or to the member of an archive. If you specify a relative or full path name (that is, a name containing one or more / characters), the file is used directly, and no search of directories specified in the LibraryPath is performed. If you specify a base name (that is, a name containing no / characters), a search is performed of the directory you specify in the LibraryPath parameter (see below).
Flags
Modifies the behavior of loadAndInit. If no special behavior is required, set the value to 0 (or 1). The possible flags are:
L_LIBPATH_EXEC
Specifies that the library path used at program execution time be prepended to any library path specified in the loadAndInit call. You should use this flag.
L_NOAUTODEFER
Specifies that any deferred imports must be explicitly resolved by the use of the loadbind routine.
L_LOADMEMBER
Specifies that the FilePath is the name of a member in an archive. The format is archivename.a(member).
LibraryPath
Points to the default library search path.

Return values

Upon successful completion, the loadAndInit function returns the pointer to function for the entry point (or data section) of the shared library.

If the loadAndInit function fails, a null pointer is returned, the module is not loaded or initialized, and the errno global variable is set to indicate the error.