I have wrote several DBA utilities, in Windows, it can run under 8i/9i/10g client, but in Linux/Unix, it require the Oracle client version library on which compiled when run. Finally I found a solution.
Found a development machine, we will modify the script "genclntsh" under $ORACLE_HOME/bin first as following:
#Change to:
# 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
LIB_DIR=${ORACLE_HOME}/${LIB} # lib. destination directory
#
# 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
LIB_DIR=${ORACLE_HOME}/${LIB} # lib. destination directory
Second, run genclntsh (For 32 bit client library on 64Bit unix, add command option "-32"), do not run this on server host with database running:
Third, We now can use gcc to compile the OCI program as following:
gcc -o ocidemo.bin ocidemo.c -I${ORACLE_HOME}/rdbms/demo -L${ORACLE_HOME}/lib -lclntsh -Wl,-Bdynamic
Forth, Write a shell executable to run the OCI program, for example (ocidemo.bin):
#!/bin/sh
if [ "A${ORACLE_HOME}A" = "AA" ]; then
echo "ORACLE_HOME environment variable not setted."
exit
fi
if [ "A${LD_LIBRARY_PATH}A" = "AA" ];then
LD_LIBRARY_PATH=/lib:/usr/lib
fi
if [ -d ${ORACLE_HOME}/lib32 ]; then
LD_LIBRARY_PATH=${ORACLE_HOME}/lib32:${LD_LIBRARY_PATH}
else
LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${LD_LIBRARY_PATH}
fi
export LD_LIBRARY_PATH
ocidemo.bin $*
I have test this method on RedHat Linux and Solaris, so all my OCI based utilities are ok to run under 8i/9i/10g version client.