最近我把gcc从4.1.2升级到了5.2.0。
这导致与OCCI库的链接错误:
我要运行的源代码:

#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);
}

联动错误:
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

我注意到未定义的引用包含c++11相关的符号,我想这与我正在使用的新gcc编译器有关。
occicontrol.h的函数声明
occi_std_namespace::string getstring(元数据::attrid attrid)
我使用的是centos 6.6和最新的occi版本instantclient basiclite linux.x64-12.1.0.2.0。
有什么想法吗?
谢谢,
大卫

最佳答案

这几乎可以肯定是由于gcc 5中的新abi与occi库所期望的abi之间不兼容。
occi库显然是使用gcc 4.x创建的
5 STD:一个新的ABI,它包括STD::String的“短字符串优化”,并且与C++ 11兼容(它不允许在GCC 4 .x中使用的STD::字符串的引用计数实现)。
在构建代码之前,您可以尝试将glibcxx定义为使用cxx11 abi到0,这将导致gcc 5使用旧的abi。
请注意,必须使用相同的abi编译所有内容才能一起工作,因此您可能希望设置全局构建标志。(例如,对于cmake,您可以将-dcmake_cxx_flags=“-d_glibcxx_use_cxx11_abi=0”添加到cmake命令行)。
此外,注意到,当尝试使用CLAN构建OCI和实现LBC+++(http://libcxx.llvm.org/)时,也存在类似的问题。(这就是咬我的那个)。
您可以在https://gcc.gnu.org/gcc-5/changes.html#libstdcxxhttps://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html找到更多信息

关于linux - GCC 5的OCCI链接错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32309029/

10-11 22:43
查看更多