Using Oracle Instant Client

You can build C/C++ applications that use Oracle Instant Client and connect to an Oracle AI Database server. If you want to build a 64-bit application and use sdk/demo/demo.mk file, then perform the following steps:

  1. Edit the sdk/demo/demo.mk file and set:

    1. CC variable to your g++ location
    2. cc variable to your gcc location
    3. ICLIBHOME variable to the path to the installed Instant Client libraries. For example, if the libraries are located in /home/oracle/OTN/instantclient_23_26/, then set:

      ICLIBHOME=/home/oracle/OTN/instantclient_23_26/
    4. ICINCHOME variable to $(ICLIBHOME)/sdk/ directory
    5. CCINCLUDES variable to the location(s) of your application's header files. For example, if your application's header files reside in /home/app_headers directory, then set:

      CCINCLUDES=-I$(ICINCHOME)include -I/home/app_headers/
    6. CCFLAGS variable to your application's other compile options.The recommended compilation options are as follows:
      -DMAC_AARCH64 -D_GNU_SOURCE -D_REENTRANT -g -arch arm64 -mcpu=apple-m1 -I$(ICINCHOME)include

      Run make -f demo.mk buildoci EXE=cdemo81 OBJS=cdemo81.o for a working demonstration of the recommended options.

    7. CCLIB variable to the libraries your application depends on and their location. For example, if your application depends on /home/app_libs/libA.so, then add -L/home/app_libs -lA to CCLIB.
    8. LDFLAGS variable to your application's other link options. The recommended link options are as follows:
      -arch arm64 -L$(ICLIBHOME) -locci -lclntsh -lpthread

      Run make -f demo.mk buildoci EXE=cdemo81 OBJS=cdemo81.o for a working demonstration of the recommended options.

  2. Compile your C/C++ application by running make -f demo.mk buildocci EXE=exename OBJS= list_of_dependent_objects.
  3. Set JAVA_PATH in the ott script to the location of libocijdbc23.dylib, if you notice the following issue while building your C++ application:

    Exception in thread "main" java.lang.UnsatisfiedLinkError: no ocijdbc23 in
          java.library.path
        JAVA_PATH=-Djava.library.path=location_of_libocijdbc23
  4. If your application has not been compiled with rpaths, update the DYLD_LIBRARY_PATH environment variable with the list of directories containing the libraries your application depends on. For example:

    export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:/home/oracle/OTN/instantclient_23_26/:/home/app_headers/
  5. If you intend to colocate the optional Oracle configuration files such as tnsnames.ora with the Oracle Instant Client, then move these files to the network/admin subdirectory. This is the default Oracle configuration directory for applications linked with this Oracle Instant Client. Alternatively, you can move the Oracle configuration files to another, accessible directory. Then set the environment variable TNS_ADMIN to that directory name.
  6. To use binaries such as sqlplus from the SQL*Plus package or any other Oracle Instant Client package, update your PATH environment variable. For example:

    PATH=$PATH:/home/oracle/OTN/instantclient_23_26/

Related Topics

Configuring Pro*C/C++

Verify that the PATH environment variable setting includes the directory that contains the C compiler executable. The default directory for the gcc compiler executable is /usr/bin.

Note:

To suppress ISO C99 Errors/Warnings, use the option -Wno-error= or --std=gnu89 while compiling C programs. Always include stdio.h before stdlib.h in pc programs.

Related Topics