最近我将我的 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
我注意到 undefined reference 包含 c++11 相关符号,我猜这与我正在使用的新 gcc 编译器有关。
occiControl.h 的函数声明
OCCI_STD_NAMESPACE::string getString(MetaData::AttrId attrid)
我使用的是 Centos 6.6 和最新的 OCCI 版本 instantclient-basiclite-linux.x64-12.1.0.2.0。
有什么想法吗?
谢谢, 大卫
最佳答案
这几乎可以肯定是由于 gcc 5 中的新 ABI 与 OCCI 库预期的 ABI 不兼容所致。
- OCCI 库显然是使用 gcc 4.x 创建的
- gcc 5 引入了一个新的 ABI,其中包括 std::string 的“短字符串优化”,并且与 C++11 兼容(它不允许使用 std::string 的引用计数实现在 gcc 4.x 中)。
您可以在构建代码之前尝试将#defining _GLIBCXX_USE_CXX11_ABI 设置为 0,这将导致 gcc 5 使用旧的 ABI。
- 请注意,必须使用相同的 ABI 编译所有内容才能协同工作,因此您可能希望将其设置为全局构建标志。 (例如,使用 CMake,您可以将 -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0"添加到 CMake 命令行)。
另外,请注意,在尝试使用 OCCI 和 clang 及其 libc++ 实现 (http://libcxx.llvm.org/) 进行构建时,也存在类似的问题。 (这是咬我的那个)。
您可以在以下位置找到更多信息:https://gcc.gnu.org/gcc-5/changes.html#libstdcxx和 https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
关于linux - 与 gcc 5 的 OCCI 链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32309029/