<- QuickStarts


This Quickstart covers using GCC with OCILIB to create applications that can use Oracle. According to the TIOBE Index C is and continues to be the most used computer language. The GNU Compiler Collection (GCC) was developed to be 100% free software, free in the sense that it respects the user's freedom. This includes not being bound to any particular proprietary constraints and limitations.

TDM-GCC is a compiler suite for Windows that combines the most recent stable release of the GCC toolset and the open-source MinGW runtime APIs. It can create 32-bit or 64-bit binaries for any version of Windows. OCILIB is an open source Oracle driver that delivers efficient access to Oracle databases. OCILIB may very well be the easiest way to connect to Oracle using C or C++. This Quickstart example focuses on creating 32-bit Windows applications to connect to a modern an Oracle database.


Other Useful Links

Install Oracle InstantClient

  1. Unset your ORACLE_HOME variable.
  2. Run setup.exe for InstantClient.
  3. (x) InstantClient Software
  4. Software Location
    Path: c:\app\oracle\product\\ic32
  5. Install
  6. Close
  7. Reset your ORACLE_HOME variable.
 Note: This will change your PATH as so: c:\app\oracle\product\\ic32;PATH
       Which in turn enables the path to the Oracle InstantClient oci.dll.

GCC Installation

  1. Run setup.exe
  2. If you do not have Internet access:
    [ ] Disable the check for updated files on the TDM-GCC server
  3. Select the Create button.
  4. Accept License by selecting Next button.
  5. Use the default location: C:\TDM-GCC-32 by selecting Next button.
  6. Use the default components by selecting the Install button.
    Note: The ...\bin directory will be added to the PATH variable.
  7. Once Completed Successfully select the Next button.
  8. Select the Finish button.
    Reading the README file can be useful. ;-)

Set Environment

  • Ensure the following is in your PATH variable: C:\TDM-GCC-32\bin;
    Note this is all the provided MinGW Command Prompt (mingwvars.bat) does.
  • Create the environment variable C_INCLUDE_PATH to C:\ocilib\include;
  • Create the environment variable LIBRARY_PATH to C:\ocilib\lib32;

Test GCC

  1. Open a the provided MinGW Command Prompt.
    This runs the mingwvars.bat to set your environment.
  2. Run the following command: gcc --version
  3. You should see the gcc version and a small banner.

Create a Test GCC Application

  1. Go to your C:\app\gcc directory.
  2. Create a file with the contents shown below as hello.c.
  3. Compile it using this command line: gcc -Wall -o hello.exe hello.c
  4. Run it by entering: hello
  5. You should see the famous Hello World! message displayed.
#include "stdio.h"

int main() {
   printf("Hello World!\n");
   return 0;

Test Windows Environment

  1. Create a file with the contents shown below as: helloWin.c
  2. Compile the below using the command line: gcc -Wall -o helloWin.exe helloWin.c
  3. Run it by entering: helloWin
  4. You should see a message box window displayed.
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    LPSTR lpCmdLine, int nCmdShow) {

    MessageBox(NULL, "Hello Windows!", "Note", MB_OK|MB_ICONINFORMATION);
    return 0;

OCILIB Installation and Test

  1. Unzip the to C:\ocilib
  2. Create a file with the contents shown below as oratest.c entering your Oracle connection values where indicated.
  3. Compile it using this command line:
    gcc -Wall -o oratest.exe oratest.c -L. -lociliba -DOCI_CHARSET_ANSI -DOCI_API=__stdcall
  4. Run it by entering: oratest
  5. You should see the the date displayed.
#include "ocilib.h"
#include "stdio.h"

void err_handler(OCI_Error *err) {
     "code: ORA-%05i\n"
     "msg:  %s\n"
     "sql:  %s\n",

int main(int argc, char *argv[]) {
    OCI_Connection *cn;
    OCI_Statement  *st;
    OCI_Resultset  *rs;	

    if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT)) return EXIT_FAILURE;

    cn = OCI_ConnectionCreate("InstanceName", "UserName", "Password", OCI_SESSION_DEFAULT);
    if (cn == NULL) {
      OCI_Error *err = OCI_GetLastError();
      printf("errcode %d, errmsg %s", OCI_ErrorGetOCICode(err), OCI_ErrorGetString(err) );	

    st  = OCI_StatementCreate(cn);

    OCI_ExecuteStmt(st, "SELECT sysdate FROM dual");

    rs = OCI_GetResultset(st);

    while (OCI_FetchNext(rs)) {
       printf("code: %i, name %s\n", OCI_GetInt(rs, 1)  , OCI_GetString(rs, 1));
       printf("\n%d row(s) fetched\n", OCI_GetRowCount(rs));

    return EXIT_SUCCESS;

Compile and Run Within Notepad++

-- Create Run Item
Press F6 then paste the below.

ENV_SET PATH = $(SYS.PATH);C:\app\oracle\product\\ic32;
ENV_SET C_INCLUDE_PATH = C:\ocilib\include;
ENV_SET LIBRARY_PATH = C:\ocilib\lib32;

cmd /c del $(CURRENT_DIRECTORY)\$(NAME_PART).exe
    -L. -lociliba -DOCI_CHARSET_ANSI -DOCI_API=__stdcall

Save as: GCC Run

Press F6 then paste the below.

ENV_SET PATH = $(SYS.PATH);C:\app\oracle\product\\ic32;
ENV_SET C_INCLUDE_PATH =  C:\TDM-GCC-32\include;C:\ocilib\include;
ENV_SET LIBRARY_PATH =C:\TDM-GCC-32\lib;C:\ocilib\lib32;

echo $(SYS.PATH)

cmd /c del $(CURRENT_DIRECTORY)\$(NAME_PART).exe
    -L. -lociliba -DOCI_CHARSET_ANSI -DOCI_API=__stdcall

Save as: GCC Run Win Res

-- Create NppExec Item
Go to Advance Options within NppExec plugin,

 A. Check the box at the top that says "Place to the Macros Submenu"
 B. Select script from "Associated Script" combo box. It will automatically fill in the "Item Name".
 C. Now click the "Add/Modify" button.
 D. Click OK. This will exit the Advanced Options box and say that NotePad++ needs to be restarted.

-- Assign to HotKey

 A. Navigate to: Settings -> Shortcut Mapper -> Plugin Commands -> GCC Run
 B. Right-Click -> Modify
 C. Select Ctrl-F1 (or other combo you desire)

<- QuickStarts