2

I am trying to develop a two-tier program, and for that, I need to connect my program to a database (Oracle in this case), through the OCCI interface using connection pools. I have linked the occi.h header file and directory in CodeBlocks already, but when I try to compile, it displays this error:

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

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

||error: ld returned 1 exit status| ||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|

Does anyone understand what this error means? I'm no ace C++ programmer, so please bear with me!

This is a demo code where the error occurs:

#include <iostream>
#include <occi.h>
#include <iomanip>
using namespace oracle::occi;
using namespace std;

class occipool {
  private:
   Environment* env;
   Connection* con;
  Statement* stmt;

 public:
 /**
 * Constructor for the occipool test case.
 */
  occipool() {
    env = Environment::createEnvironment(Environment::DEFAULT);
  }    // end of constructor occipool ()

 /**
* Destructor for the occipool test case.
*/
 ~occipool() {
  Environment::terminateEnvironment(env);
 }    // end of ~occipool ()

 /**
* The testing logic of the test case.
*/
 dvoid select() {
cout << "occipool - Selecting records using ConnectionPool interface"
     << endl;
const string poolUserName = "name";
const string poolPassword = "password";
const string connectString = "name";
const string username = "name";
const string passWord = "password";
unsigned int maxConn = 5;
unsigned int minConn = 3;
unsigned int incrConn = 2;
ConnectionPool* connPool = env->createConnectionPool(
    poolUserName, poolPassword, connectString, minConn, maxConn, incrConn);
try {
  if (connPool)
    cout << "SUCCESS - createConnectionPool" << endl;
  else
    cout << "FAILURE - createConnectionPool" << endl;
  con = connPool->createConnection(username, passWord);
  if (con)
    cout << "SUCCESS - createConnection" << endl;
  else
    cout << "FAILURE - createConnection" << endl;
} catch (SQLException ex) {
  cout << "Exception thrown for createConnectionPool" << endl;
  cout << "Error number: " << ex.getErrorCode() << endl;
  cout << ex.getMessage() << endl;
}

cout << "retrieving the data" << endl;
stmt = con->createStatement("SELECT ID, dept_name FROM p_worker");
ResultSet* rset = stmt->executeQuery();
while (rset->next()) {
  cout << "author_id:" << rset->getInt(1) << endl;
  cout << "author_name:" << rset->getString(2) << endl;
}
stmt->closeResultSet(rset);
con->terminateStatement(stmt);
connPool->terminateConnection(con);
env->terminateConnectionPool(connPool);

cout << "occipool - done" << endl;
}  // end of test (Connection *)

};  // end of class occipool

  int main(void) {
 string user = "name";
 string passwd = "password";
 string db = "name";

 occipool* demo = new occipool();

 demo->select();
 delete demo;

  }  // end of main ()
Obsidian Age
  • 41,205
  • 10
  • 48
  • 71
avarus
  • 37
  • 5
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Richard Critten Feb 28 '17 at 23:34
  • Although small in your example code, you should try to avoid "dynamic" connection pools. – BobC Mar 01 '17 at 05:22

1 Answers1

0

Are you linking with libocci.so and -libclntsh.so libraries?

It's needs.

filosofisto
  • 105
  • 7