Recently I've upgraded my gcc from 4.1.2 to 5.2.0.
This caused a linkage error with the OCCI library:
Source Code I'm trying to run:
#include <iostream>
#include <occi.h>
using namespace oracle::occi;
using namespace std;
int main (int argc, char *argv[])
{
Environment *env;
Connection *conn;
oracle::occi::MetaData metaData = conn->getMetaData ((char *)"PERSON_OBJ");
metaData.getString(MetaData::ATTR_NAME);
return(0);
}
The linkage error:
gmake -f /home/davidd/temp.mak CFG=Debug
g++ -g "-Wl,-rpath,/omniqdir/arch/x86_64/release/lib:/omniqdir/instantclient_12_1:/usr/lib,-rpath-link,/omniqdir/arch/x86_64/release/lib:/omniqdir/instantclient_12_1:/usr/lib,-ldl,-lpthread" /omniqdir/arch/x86_64/release/lib/libjemalloc.so -o "Debug/temp" Debug/temp.o /omniqdir/instantclient_12_1/libocci.so /omniqdir/instantclient_12_1/libclntsh.so
Debug/temp.o: In function `main':
temp.cpp:(.text+0xac): undefined reference to `_ZNK6oracle4occi8MetaData9getStringB5**cxx11**ENS1_6AttrIdE'
collect2: error: ld returned 1 exit status
gmake: *** [Debug/temp] Error 1
I've noticed that the undefined reference contains c++11 related symbols, which i guess have to do with the new gcc compiler I'm using.
Function declaration from occiControl.h
OCCI_STD_NAMESPACE::string getString(MetaData::AttrId attrid)
I'm using Centos 6.6 and latest OCCI version instantclient-basiclite-linux.x64-12.1.0.2.0.
Any ideas?
Thanks, David
This is almost certainly due to incompatibility between the new ABI in gcc 5 and the ABI expected by the OCCI libraries.
- The OCCI libraries were apparently created using gcc 4.x
- gcc 5 introduces a new ABI which includes, among other things, the "short string optimization" for std::string, and is compatible with C++11 (which disallows the reference-counted implementation of std::string used in gcc 4.x).
You can try #defining _GLIBCXX_USE_CXX11_ABI to 0 before building your code, which will cause gcc 5 to use the old ABI.
- Note that EVERYTHING must be compiled with the same ABI to work together, so you may want to make that setting a global build flag. (E.g., with CMake, you would add -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" to the CMake command line).
Also, note that a similar problem exists when trying to build using OCCI with clang and its implementation of libc++ (http://libcxx.llvm.org/). (This is the one that bit me).
You can find out more at: https://gcc.gnu.org/gcc-5/changes.html#libstdcxx and https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
I had a similar problem in Solaris 11. It was resolved with Linker options:
-m64 -lCstd
I hope it helps.
来源:https://stackoverflow.com/questions/32309029/occi-linkage-error-with-gcc-5