SOCI
Simple Oracle Call Interface (and more)

Library structure, files and compilation

The SOCI library has the following structure:



The soci.h and soci.cpp are the main files of the library - the ones that you have to directly interface with. The soci-common.h file (located in the backends/ directory of the library distribution) is an internal abstract interface to the actual backends, which are needed to perform operations on the given database server. Normally, the C++ client program needs to interface with the soci.h header file only, unless it needs to gain direct access to the internal handles of the backend.
The gray boxes above indicate that the SOCI library is extensible and that there are two aspects of this extensibility: more backends can be added, and more interfaces (possibly for other languages) can be defined to reuse the already existing backends.

Everything in SOCI (and in soci.h in particular) is declared in the namespace SOCI. All code examples presented in this documentation assume that your code begins with something like:

#include "soci.h"
// other includes

using namespace SOCI;

// ...

Compilation of the client program requires that the SOCI header files are all visible and accessible to the compiler. Moreover, the backend .cpp files (those which are needed) should be compiled and linked into the final executable. For this, the native libraries provided by each database server should be visible to the compiler and linker - the actual steps that need to be taken depend on the compiler being used.
The following instructions consider the Oracle backend:

On MS Windows, in MSVC++7

In Project Properties:

  1. In C/C++ - General:
    Add the Additional Include Directory where the oci.h file is located (it can be something like C:\Oracle\Ora81\oci\include).
  2. In Linker - General:
    Add the Additional Library Directory where the oci.lib file is located (it can be something like C:\Oracle\Ora81\oci\lib\msvc).
  3. In Linker - Input:
    Add the Additional Dependency: oci.lib.

When executing programs, the oci.dll file should be located in the path where it can be found. Be careful when using many different Oracle tools, because they may overwrite each other's oci.dll versions. The "correct" oci.dll for running the program compiled as above is located somewhere near the oci.lib, for example in C:\Oracle\Ora81\BIN.

On Unix-like systems

The OCI library is usually inside the libclntsh.so or libclntsh.sl library (depending on the actual system), so you have to add the -lclntsh option for linking and -L option to provide the path to the linker. Of course, the -I compiler option will be needed to provide the location of the oci.h header file. Look inside the $ORACLE_HOME directory to find where these files are located - it may depend both on the Unix flavour and the Oracle version installed, but likely locations are $ORACLE_HOME/rdbms/demo for oci.h and $ORACLE_HOME/lib for libclntsh.so.

Note that together with the SOCI library, there is a set of test programs provided. Their Makefiles can be a good starting point to find out correct compiler and linker options.

Previous (Contents)
Next (Errors)


Copyright © 2004-2006 Maciej Sobczak, Stephen Hutton