OCILIB Tutorials v5.0.0
Beginner

Prerequisites — database & Oracle client

Objectives — by the end of this page you will be able to:

You need three things

  1. An Oracle database to connect to.
  2. The Oracle client libraries — OCILIB talks to the database through them.
  3. A C and/or C++ toolchain — building OCILIB from source needs C11 / C++17; using an installed OCILIB from C needs no specific standard (plain C headers and ABI).

Getting a database

Any of these works; pick the easiest for you:

Option Notes
Oracle XE (free) Full-featured free edition. Download the installer for Windows or Linux from oracle.com. Gives you localhost:1521/XEPDB1 after a default install.
Docker docker run -d -p 1521:1521 gvenzl/oracle-xe — fastest path on Linux/macOS/Windows with Docker. Same connect string after startup.
Existing server Ask your DBA for a user/schema; note the host:port/service string.

The tutorials assume a schema you can write to. The SCOTT/tiger tradition is used in samples but any user works — that's what the environment variables below are for.

Getting the Oracle client (Instant Client)

OCILIB never talks to the server directly — it loads Oracle's client library at run time. The Instant Client is the lightweight, free way to get it.

Windows

  1. Download Instant Client Basic (x64) from oracle.com — a zip like instantclient-basic-windows.x64-23.x.x.x.zip.
  2. Unzip to a permanent folder, e.g. C:\oracle\instantclient_23_x.
  3. Add that folder to your PATH (System → Environment Variables), or copy the DLLs next to your executable.
  4. If you will build OCILIB in linkage mode, also download the SDK package (headers + oci.lib) into the same folder.

Linux

# Oracle Linux / RHEL-family
sudo dnf install oracle-instantclient-release-23ai-el9
sudo dnf install oracle-instantclient-basic oracle-instantclient-sqlplus

# or manually:
unzip instantclient-basic-linux.x64-23.*.zip -d /opt/oracle
export LD_LIBRARY_PATH=/opt/oracle/instantclient_23_x:$LD_LIBRARY_PATH

Runtime import needs no SDK

If you build OCILIB with --with-oracle-import=runtime (opt-in on Linux), it locates libclntsh.so / oci.dll itself at run time — you do not need Oracle headers to compile. Without it, the default linkage mode needs the Instant Client SDK.

Environment variables used by all samples

Set these once; every tutorial program reads them so no credentials live in code:

# Linux / macOS / WSL — add to ~/.bashrc
export OCILIB_DEMO_DB="localhost:1521/XEPDB1"
export OCILIB_DEMO_USR="scott"
export OCILIB_DEMO_PWD="tiger"

Toolchain

Platform Compiler
Windows Visual Studio 2022+ (C17 + /std:c++17)
Linux gcc ≥ 10 or clang ≥ 12 (-std=c11 / -std=c++17)

Try it yourself

  1. Verify the client loads: run sqlplus $OCILIB_DEMO_USR/$OCILIB_DEMO_PWD@$OCILIB_DEMO_DB (or sqlplus scott/tiger@localhost:1521/XEPDB1) — if it connects, everything you need is installed.
  2. Create the tutorial schema: sqlplus usr/pwd@db @doc/tutorials/assets/sql/tutorial-schema.sql

Common pitfalls

Recap

Next: build OCILIB itself — Windows on the left, Linux below it in the TOC.