OCI Demo Linking Error

Oracle call interface (OCI) demo programs come with database software installation. For the release 21.7 you can find them in the directory ${ORACLE_HOME}/sdk/demo/.

Linking is failing:

make -f demo.mk buildoci EXE=cdemo81 OBJS=cdemo81.o
rm -rf SunWS_cache
/usr/bin/g++ -o cdemo81 -g cdemo81.o -L../../ -locci -lclntsh -lpthread
/usr/bin/ld: cannot find -locci
/usr/bin/ld: cannot find -lclntsh
collect2: error: ld returned 1 exit status
make: *** [demo.mk:81: buildoci] Error 1

The error message above tells us that the Oracle client library libclntsh and OCI library libocci couldn’t be found. The both libraries are contained in the lib directory of the Oracle database software installation:

ls ${ORACLE_HOME}/lib/libclntsh.so
/u00/oracle/orabase/product/21.7.0.0.220719_a/lib/libclntsh.so

ls ${ORACLE_HOME}/lib/libocci.so
/u00/oracle/orabase/product/21.7.0.0.220719_a/lib/libocci.so

LD_LIBRARY_PATH is pointing to the correct directory:

env | grep LD_LIBRARY_PATH
LD_LIBRARY_PATH=/u00/oracle/orabase/product/21.7.0.0.220719_a/lib

But LD_LIBRARY_PATH doesn’t help here because it is used only during runtime and not during linking.

The library directory path during linking must be specified with the -L option. There’s an entry in the makefile demo.mk but it is set to ${ORACLE_HOME} instead of ${ORACLE_HOME}/lib.

ICLIBHOME=../../
ICLIBPATH=-L$(ICLIBHOME)

With the following correction

#ICLIBPATH=-L$(ICLIBHOME)
ICLIBPATH=-L$(ICLIBHOME)/lib

the demo program links and compiles without problems:

make -f demo.mk buildoci EXE=cdemo81 OBJS=cdemo81.o
rm -rf SunWS_cache
/usr/bin/g++ -o cdemo81 -g cdemo81.o -L../..//lib -locci -lclntsh -lpthread

ls cdemo81
cdemo81
Thanks for sharing

Nenad Noveljic

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.