'Compatibility issues with Oracle OCCI and g++ 7.1
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?
Solution 1:[1]
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
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hamdi Hamdi |
Solution 2 | virus00x |