How to compile version independent OCI program on Linux/Unix?

Links: http://www.dbatools.net/experience/oracle-oci-version.html

    OCI is a very effective program interface to access Oracle database, I have wrote several DBA utilities with OCI interface. On Windows the compiled binary can run under Oracle 8i/9i/10g client environment. But on Linux/Unix, it cannot, because it requires a version dependent oracle client library (libclntsh.so.version), we can check this with "ldd" utility.

$ ldd ociuldr.bin
   libclntsh.so =>  /oracle/home/8174/lib32/libclntsh.so.8.0
   libclntsh.so =>  /oracle/home/9205/lib32/libclntsh.so.9.0
   libclntsh.so =>  /oracle/home/10g/lib32/libclntsh.so.10.1
   ......

    But actually, for every Oracle version, there is a soft link for the Oracle client library. The soft link name is version independent, the key is how to let my program know this.

$ ls -l libclntsh.so
  libclntsh.so -> libclntsh.so.8.0
  libclntsh.so -> libclntsh.so.9.0
  libclntsh.so -> libclntsh.so.10.1

    Finally I found a way, we just need to modify a shell script named "genclntsh", this script is used to relink the client library. We need to change the following lines. Following are the old lines.

# Library names and locations
CLNT_NAM=clntsh                  # (short) library name
CLNT_VER=9.0                     # library version number
CLNT_LNK=lib${CLNT_NAM}.so       # name of symlink to library
CLNT_LIB=${CLNT_LNK}.${CLNT_VER} # actual library file name

    And we change it as following. I just shift "CLNT_LNK" and "CLNT_LIB" to make the soft link a real library file on develop machine.

# Library names and locations
CLNT_NAM=clntsh                  # (short) library name
CLNT_VER=9.0                     # library version number
CLNT_LIB=lib${CLNT_NAM}.so       # name of symlink to library
CLNT_LNK=${CLNT_LNK}.${CLNT_VER} # actual library file name

    Then you need to run the following command to relink the library file.

genclntsh
genclntsh -32 #for 32 bit library on 64 bit Oracle

    Then you can start to compile your OCI program now, I compiled some utilities under 10g client, and they can be run under 8i/9i/10g version without recompile.

« Previous | Main | Next »

Powered by
Movable Type 5.01