Appendix B. Preloading Libraries at Runtime

B.1 Preloading Libraries

Linux and many UNIX platforms support environment variables that provide a way to add libraries to a dynamically-linked executable at runtime. On Linux and UNIX based systems, the name of the variable is LD_PRELOAD.

When an MTS library appears first in these environment variables, the application uses the MTS allocator instead of the system allocator. This Appendix describes the environment variables and shows the syntax for setting environment variables in the most common shells.

B.2 Setting LD PRELOAD

Linux and UNIX based systems support LD_PRELOAD.

When LD_PRELOAD contains a list of libraries, the dynamic linker loads the libraries specified before loading any shared libraries the executable requires. The linker resolves symbols in the order in which shared libraries are loaded. Therefore, libraries listed in the environment variable can replace libraries specified at link time. Different shells have different syntax for setting environment variables. In csh and variants such as tcsh, use the setenv command as shown below:

setenv name value

For example, the command line below sets the environment variable LD_PRELOAD to the value /opt/MTS/lib/libmtsfm32.so:

setenv LD PRELOAD /opt/MTS/lib/libmtsfm32.so

When setting LD_PRELOAD, substitute the /opt/MTS/lib in the command line above with the full path to the appropriate MTS library.

In sh, ksh, and variants such as ash, bash, jsh, pdksh or zsh, set the variable and then export the variable as shown below:

name=value
export name

For example, the command line below sets the environment variable LD_PRELOAD to the value /opt/MTS/lib/libmtsfm32.so:

LD PRELOAD=/opt/MTS/lib/libmtsfm32.so
export LD PRELOAD

When setting LD_PRELOAD, substitute the /opt/MTS/lib in the command line above with the full path to the appropriate MTS library. Note that multithreaded versions of the MTS library require the pthread library, so the full path to the pthread library must also be included in the LD_PRELOAD environment variable.