2 Replies Latest reply: Jan 17, 2014 10:59 AM by ddevienne RSS

Getting A Basic OCI C++ Application To Compile

da2a6f06-064c-45cc-8735-e01ca679708f Newbie
Currently Being Moderated

Can someone please tell me what I am missing?

 

I downloaded Oracle instantclient-basic-nt-12.1.0.1.0.zip and instantclient-sdk-nt-12.1.0.1.0.zip and extracted both to c:\oracle\

I then went into visual studio 2013 and created a Win32 Console application with all default parms.

 

I then went into project -> properties -> C/C++ -> General -> Additional Include Directories and added my include path C:\oracle\sdk\include

I then went into project -> properties -> Linker -> General -> Additional Library Directories and added C:\oracle\sdk\lib\msvc\vc11

I then went into project -> properties -> Linker -> Input -> Additional Dependancies and added oraocci12.lib

 

The program compiles but when I debug i get a RUNTIME error that says "The program can't start because oraocci12.dll is missing from your computer.  Try reinstalling the program to fix this problem.  But I know the file exists in C:\oracle\sdk\lib\msvc\vc11\oraocci12.lib

 

What am I doing wrong?  Any help is greatly appreciated!

 

This is the code if it makes a difference

 

#include "stdafx.h"

#include <iostream>

#include <occi.h>

 

using namespace std;

 

int _tmain(int argc, _TCHAR* argv[])

{

    oracle::occi::Environment* environment;

    oracle::occi::Connection *con;

    oracle::occi::Statement* stmt;

    oracle::occi::ResultSet* res;

 

    try{

 

        environment = oracle::occi::Environment::createEnvironment(oracle::occi::Environment::DEFAULT);

        con = environment->createConnection("gldbuser", "gldbuser", "MYDATABSE");

 

        stmt = con->createStatement("select * from example");

        res = stmt->executeQuery();

 

        while (res->next())

            std::cout << res->getInt(1) << "  " << res->getString(2) << std::endl;

 

        stmt->closeResultSet(res);

        con->terminateStatement(stmt);

        environment->terminateConnection(con);

 

    }

    catch (oracle::occi::SQLException &e){

        std::cout << e.what();

    }

 

    return 0;

 

}

  • 2. Re: Getting A Basic OCI C++ Application To Compile
    ddevienne Newbie
    Currently Being Moderated

    Your setup is correct, to build with OCCI.

     

    You are linking with oraocci12.lib from <instantclient-12.1.0.1.0>\sdk\lib\msvc\vc11.

     

    But at runtime you also need oraocci12.dll from <instantclient-12.1.0.1.0>\.

     

    oraocci12.lib is an "import" library, not a normal "static" library. It contains only stubs to symbols which are really implemented in oraocci12.dll.

     

    So you app must be able to find the DLL, and Windows finds DLL from the PATH (or Path) environment variable. There are several ways to configure your Path to include <instantclient-12.1.0.1.0>:

    1. system windows, via the system environment variables
    2. in a .bat, which then launches VS (thus inheriting the Path)
    3. In VS, project properties, Configuration Properties> Debugging> Environment, enter Path=C:\oracle\;$(Path). Note that VS uses $(VAR), not %VAR% like DOS/.bat does.Note also that Path could be written PATH too. Open a DOS windows, and type path. It will show you the name of the path (Path or PATH or path) = its value. Use the same var name.

     

    This should be you going. --DD

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points