Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2007

    Unanswered: Makefile problem for OCCI on Oracle 9i

    Hi folks,

    I tried the following example code named "demo.cpp" on my FC4 Linux (gcc version is 4.1.0) with Oracle 9i R2 installed. I can not link the object file to an executable file. I searched with Google for quite a long time. But still have no idea. Would you please give me some help? Thanks in advance!

    The makefile is attached followed by the source code too.

    // Example C++ program using OCCI to connect to an Oracle database.
    // Only basic setup/teardown is shown, no query logic is presented.

    #include <stdlib.h>
    #include <iostream>
    #include <occi.h>

    using namespace oracle::occi;
    using namespace std;

    * Reads the environment and obtains the value of an environment
    * variable previously set by the user or system administrator.
    * If the variable var_name isn’t set in the environment this
    * function will print a warning message to STDERR then exit the
    * program.
    * @param var_name the name of the environment variable to get.
    * @return the value of the environment variable.
    const string
    get_env_string (const char * const var_name)
    char* const v = getenv(var_name);
    if (!v)
    cerr << "Environment variable "
    << var_name
    << " must be defined."
    << endl;

    return v;

    main (int argc, char* argv[])
    // Fetch our required environment variable values. The program
    // will exit if one of these can’t be obtained.
    const string user = get_env_string("ORACLE_DIRECTORY_USER");
    const string pass = get_env_string("ORACLE_DIRECTORY_PASS");
    const string osid = get_env_string("ORACLE_SID");

    // Establish the Oracle client environment. Allows the Oracle
    // libraries to allocate memory, initialize data structures, etc.
    Environment* const env = Environment::createEnvironment(

    // Open a connection to the database, then close it.
    int ret = 0;
    Connection* const con = env->createConnection(user, pass, osid);

    cout << "Connected as " << user << "@" << osid << "." << endl;

    cout << "Closing connection." << endl;

    catch (SQLException ea)
    // We couldn’t connect. what() will give us the Oracle error
    // code and message, so we can troubleshoot the issue.
    cerr << "Can’t connect: " << ea.what();
    ret = 1;

    // Cleanup the environment. It is a very good idea to let Oracle
    // cleanup before your program terminates.

    return ret;

    The Makefile is as follows:

    -I$(ORACLE_HOME)/rdbms/public \
    -I$(ORACLE_HOME)/plsql/public \
    -I$(ORACLE_HOME)/network/public \

    #CC_FLAG=-Wno-deprecated -fPIC -march=i486
    LIB=$(ORACLE_LIBS) -lclntsh -locci


    @echo "Link $(OBJ) to $(PRG) begin......"
    $(CC) $(CC_FLAG) $(INC) $(LIB) -o $@ $<
    @echo "Link $(OBJ) to $(PRG) end......"

    @echo "Compile $(OBJ) begin......"
    $(CC) $(CC_FLAG) $(INC) $(ORACLE_LIBS) -c $<
    @echo "Compile $(OBJ) end......"

    @echo "Removing linked and compiled files......"
    rm -f $(OBJ) $(PRG)

    Although I can compile demo.cpp to demo.o, I fail to link demo.o to demo. The error message is:

    Compile demo.o begin......
    g++ -Wall -I/oracle/920/rdbms/demo -I/oracle/920/rdbms/public -I/oracle/920/plsql/public -I/oracle/920/network/public -I/oracle/920/precomp/public -L/oracle/920/lib -L/oracle/920/rdbms/lib -c demo.cpp
    Compile demo.o end......
    Link demo.o to demo begin......
    g++ -Wall -I/oracle/920/rdbms/demo -I/oracle/920/rdbms/public -I/oracle/920/plsql/public -I/oracle/920/network/public -I/oracle/920/precomp/public -L/oracle/920/lib -L/oracle/920/rdbms/lib -lclntsh -locci -o demo demo.o
    demo.o(.text+0x1b8): In function `main':
    demo.cpp: undefined reference to `oracle::occi::Environment::createEnvironment(orac le::occi::Environment::Mode, void*, void* (*)(void*, unsigned int), void* (*)(void*, void*, unsigned int), void (*)(void*, void*))'
    demo.o(.text+0x2bf):demo.cpp: undefined reference to `oracle::occi::SQLException::SQLException(oracle:: occi::SQLException const&)'
    demo.o(.text+0x2d5):demo.cpp: undefined reference to `oracle::occi::SQLException::what() const'
    demo.o(.text+0x328):demo.cpp: undefined reference to `oracle::occi::SQLException::~SQLException()'
    demo.o(.text+0x340):demo.cpp: undefined reference to `oracle::occi::SQLException::~SQLException()'
    demo.o(.text+0x35b):demo.cpp: undefined reference to `oracle::occi::Environment::terminateEnvironment(o racle::occi::Environment*)'
    demo.o(.gcc_except_table+0x64): undefined reference to `typeinfo for oracle::occi::SQLException'
    collect2: ld returned 1 exit status
    make: *** [demo] Error 1
    Last edited by towergee; 07-02-07 at 17:47.

  2. #2
    Join Date
    Jul 2007
    I find a useful link!

    I will test it later.

    If you're getting the following error messages:

    undefined reference to `oracle:cci::Environment::createEnvironment(oracle:cci::Environment::Mode, void*, void* (*)(void*, unsigned), void* (*)(void*, void*, unsigned), void (*)(void*, void*))'


    undefined reference to `oracle:cci::Environment::terminateEnvironment(oracle:cci::Environment*)'

    then you're probably running oracle9i on redhat 8.0. to solve this, download and install the following rpm's from this redhat link:

    * compat-gcc-7.3-2.96.118.i386.rpm
    * compat-gcc-c++-7.3-2.96.118.i386.rpm
    * compat-libstdc++-7.3-2.96.118.i386.rpm
    * compat-libstdc++-devel-7.3-2.96.118.i386.rpm

    and compile with g++296 instead of g++. sure you'll be stuck with g++-2.96, but at least it will compile and run.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts