Oracle7 Administrator's Reference for UNIX
Shared Libraries and Shared Objects Support
UNIX supports shared libraries and archive libraries for Pro*C and Oracle*XA clients. Shared object code is compatible with the archive library. Shared libraries, however, are organized and linked differently from archive libraries.
Shared objects are dynamically linked and appear as a single object file containing code for every function in the library. When your program uses a function from a shared object, the content of the shared library is placed into the virtual address space of your process at run time. In addition, other programs use the code in the shared objects simultaneously at run time.
Shared libraries provide the following advantages over archives:
- Shared library code requires less disk space because it is not copied into the executables that use it.
- The system needs less physical memory because library code is shared at run time.
- Shared objects can be updated without having to relink applications that depend on them, because symbol resolution is delayed until the program actually runs.
Creating the Shared Library for Pro*C and Oracle*XA Clients
To use shared code in a program:
1. Create the shared library.
2. Create executables that use shared code.
3. Ensure that the shared library is accessible at program runtime.
$ORACLE_HOME/lib/libclntsh.so is the shared library for Oracle7 on UNIX. If you install Pro*C, the library is generated automatically by the Oracle Installer during a fresh installation. If necessary, you can also generate the library manually, using the clntsh.mk makefile in $ORACLE_HOME/rdbms/lib.
Attention: Make sure no applications using libclntsh.so are running when you rebuild libclntsh.so.
Oracle7 and Pro*C products must be installed before the shared library is generated. If you install Oracle*XA later, the Oracle Installer re-runs the makefile to include Oracle*XA in the shared library.
You must rebuild the client-side shared library when you:
- install or de-install SQL*Net version 2 protocol adapters
- apply a patch to any of the following static Oracle libraries:
- change any static operating system or optional networking libraries referenced in the $ORACLE_HOME/rdbms/lib/sysliblist file
To rebuild the shared library manually, verify that the environment variable ORACLE_HOME is set and complete the following steps:
1. Change the directory to $ORACLE_HOME/rdbms/lib.
2. Build the shared library using the make command.
Example:
$ cd $ORACLE_HOME/rdbms/lib
$ make -f clntsh.mk libclntsh
Creating Executables that Use the Shared Library
To generate executables for Pro*C and Oracle*XA programs, use $ORACLE_HOME/proc/lib/proc.mk as a makefile. A target build exists for this purpose. The EXE and OBJS variables are passed to the make command to specify the client to be built. For example:
% make -f $ORACLE_HOME/proc/lib/proc.mk \
ORA_CLIENT_LIB=shared OBJS=foo.o EXE=foo
You can also set the variable ORA_CLIENT_LIB in your environment, then generate the executable without explicitly passing in the environment variable. For example:
% make -f $ORACLE_HOME/proc/lib/proc.mk OBJS=foo.o \
EXE=foo
Using Shared Code at Runtime
At runtime, the operating system's dynamic linker must be able to find all shared objects used by an executable. You can use one of the following methods to set the search path to $ORACLE_HOME/lib for libclntsh.so.
- When you create the executable, set the environment variable LD_RUN_PATH to the directory path of the shared library at link time. This stores a list of directories in the executable itself.
Use this method if you are using setuid programs. They ignore LD_LIBRARY_PATH at runtime, to avoid security problems.
- Set the LD_LIBRARY_PATH environment variable at runtime to to the directory path of the shared library.
If the executable runs in an $ORACLE_HOME directory other than the one in which it is linked, you must set LD_LIBRARY_PATH. You can use the UNIX ldd command to determine where the dynamic linker is searching for shared objects.
See Also: The UNIX man page for the ldd command.
If the dynamic linker is unable to find the shared object, a message similar to the following appears:
$ ./sample1
ld.so.1: sample1: fatal: libclntsh.so:
can't open file: errno=2
Killed
Restrictions
Oracle*XA does not support the use of package global variables.