2

I am trying to create a C++ application with OCCI (versions 11,12,18, all lead to the same issue explained below) using gcc 7.1.

The application below compiles and runs fine with gcc 4.8.5 unter RHEL7, but throws an error ORA-24960: the attribute OCI_ATTR_USERNAME is greater than the maximum allowable length of 255 when compiled with gcc 7.1.

This question seems to address the problem, but downgrading to a lower compiler version is no option in my case, as I need to integrate the OCCI calls into a bigger application that depends on gcc 7.1.

Here's an MCVE for simply checking the connection to the DB:

#include <string>
#include <occi.h>

using namespace oracle::occi;
using namespace std;

int main()
{
  const string url = "//server:1234/ID";
  const string username = "user";
  const string password = "password";

  Environment* env = Environment::createEnvironment();
  try {
    Connection* conn = env->createConnection(username, password, url);
    cout << "Connection to " << url << " successfully established." << endl;

    env->terminateConnection(conn);
    cout << "Connection closed." << endl;
  }
  catch (const SQLException& ex) {
    cerr << "Error: " << ex.what() << endl;
  }
  Environment::terminateEnvironment (env);
}

Has anyone made any experience with this problem and knows if there is a workaround or static OCCI libraries I can link against?

andreee
  • 4,459
  • 22
  • 42
  • 1
    I tried to avoid using OCCI, g++ ABI changes from time to time and no force will make Oracle to recompile OCCI using a newer compiler. Any open-source OCI wrapper is better that OCCI. For example it already happened recently that exception thrown from OCCI could not be caught in code compiled using a newer g++, due to ABI non-compatibility. The app always segfault-ed when an exception was thrown. – ibre5041 Aug 29 '18 at 08:43
  • "Certified Compilers for OCCI (Doc ID 437957.1)" support doc has the info on compatibility - basically only (default?) compilers shipped with supported Linux distros. As ibre says, you're probably better off with the C interface and other wrappers if needed. – Mat Aug 29 '18 at 09:07
  • Which g++ 7.1 are you using - where do the packages originate from? – Christopher Jones Oct 30 '18 at 15:25

2 Answers2

1

I faced the same problem. OCCI uses old ABI although the GCC-5.0 onwards has changed the default ABI. But these GCC compilers provides dual ABI (both old and new), only we have to declare which one to use. So either add the following line as the first line of your code

# define _GLIBCXX_USE_CXX11_ABI 0

or add the following Macro to compiler command line

_GLIBCXX_USE_CXX11_ABI=0

The Real problem is that if we use libraries from multiple vendors, some of them providing the default ABI, then they wont work with the older ABI. And I have not found any solution for this problem yet.

virus00x
  • 713
  • 5
  • 12
0

Add the line below prior first include. GCC uses "std::__cxx11::string", but Intel compiler uses ""std::string, therefore you get a different structure and weird error.

# define _GLIBCXX_USE_CXX11_ABI 0
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 10 '21 at 23:27