_GLIBCXX_USE_CXX11_ABI,兼容GCC 4.8和ABI [英] _GLIBCXX_USE_CXX11_ABI, GCC 4.8 and ABI compatibility

查看:3962
本文介绍了_GLIBCXX_USE_CXX11_ABI,兼容GCC 4.8和ABI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们收到了一些针对linux编译的库(.a)(可能使用GCC 6.x编译)。



我们正在使用GCC 4.8,并且出现错误的类型:
未定义对std :: __ cxx11 :: basic_string 的引用



通常这可以通过确保所有单元已经用相同的 _GLIBCXX_USE_CXX11_ABI 标志编译来解决。
但是如果我理解正确的话,这是GCC 5.1和之后推出的。


  1. 有没有办法让GCC 4.8可以工作,或者我们需要让人们用不同的<$重新编译库c $ c> _GLIBCXX_USE_CXX11_ABI ?

  2. 我猜如果我们能够切换到GCC> = 5.1,我们可以做到这一点吗?

感谢!

解决方案

+11 ABI与海湾合作委员会4.8.2,但它是一个危险的黑客;如果可能的话,要求供应商发布使用C ++ 03 ABI( -D_GLIBCXX_USE_CXX11_ABI = 0 )编译的库或升级到GCC 5或以上。

您需要下载并安装gcc 5,以便您可以使用它的libstdc ++头文件和库,然后指示gcc 4.8将它们优先用于自己的。另外,因为gcc 4.8缺少libccdd ++ ++需要的一些内在函数,所以你需要破解它们的用法。



例如,要编译一个简单的包含< string> 的单文件应用程序:

  / usr /local/gcc-4.8.2/bin/g++ \ 
-std = c ++ 11 \
-D_GLIBCXX_USE_CXX11_ABI = 1 \
-D'__ is_trivially_copyable(...) = 0'\
-D'__ is_trivially_constructible(...)= 0'\
-D'__ is_trivially_assignable(...)= 0'\
-nostdinc ++ \
-isystem /usr/local/gcc-5.4.0/include/c++/5.4.0/ \
-isystem /usr/local/gcc-5.4.0/include/c++/5.4.0 / x86_64-unknown-linux-gnu \
-L ​​/usr/local/gcc-5.4.0/lib64
a.cpp

这很危险,因为gcc 5.4 libstdc ++不能用于gcc 4.8,并且重新定义了使用的内部函数( __ is_trivially_copyable 等)可以chan ge结构的布局或以其他方式导致您的程序和供应商的库之间的二进制不兼容。

为了运行生成的可执行文件,还需要确保动态链接器找到兼容的libstdc ++,例如通过向 /etc/ld.so.conf中添加 /usr/local/gcc-5.4.0/lib64 或使用 -Wl,-rpath /usr/local/gcc-5.4.0/lib64


We received some libraries (.a) compiled for linux (probably compiled with GCC 6.x).

We are using GCC 4.8 and we are getting the error of the type: undefined reference to std::__cxx11::basic_string when trying to link.

Normally this could be fixed by making sure all units have been compiled with the same _GLIBCXX_USE_CXX11_ABI flag. However if I understood correctly, this was introduced by GCC 5.1 and on.

  1. Is there a way to make this work with GCC 4.8 or do we need to ask the people to recompile the libraries with a different _GLIBCXX_USE_CXX11_ABI?
  2. I guess if we are able to switch to GCC >= 5.1 we can make this work?

Thanks!

解决方案

It's possible to use the C++11 ABI with gcc 4.8.2, but it's a dangerous hack; you would be far better off if at all possible to ask your vendors to ship libraries compiled with the C++03 ABI (-D_GLIBCXX_USE_CXX11_ABI=0) or to upgrade to GCC 5 or above.

You would need to download and install gcc 5 so that you can use its libstdc++ headers and libraries, then direct gcc 4.8 to use those in preference to its own. In addition, because gcc 4.8 is missing some intrinsics required by the libstdc++ shipped with gcc 5, you would need to hack out their usage.

For example, to compile a simple single-file application that includes <string>:

/usr/local/gcc-4.8.2/bin/g++ \
   -std=c++11 \
   -D_GLIBCXX_USE_CXX11_ABI=1 \
   -D'__is_trivially_copyable(...)=0' \
   -D'__is_trivially_constructible(...)=0' \
   -D'__is_trivially_assignable(...)=0' \
   -nostdinc++ \
   -isystem /usr/local/gcc-5.4.0/include/c++/5.4.0/ \
   -isystem /usr/local/gcc-5.4.0/include/c++/5.4.0/x86_64-unknown-linux-gnu \
   -L /usr/local/gcc-5.4.0/lib64
   a.cpp

This is dangerous because the gcc 5.4 libstdc++ is not designed to work with gcc 4.8, and redefining the intrinsics used (__is_trivially_copyable etc.) could change the layout of structures or otherwise cause binary incompatibility between your programs and the vendor's libraries.

In order to run the resulting executable, you would also need to ensure that the dynamic linker finds a compatible libstdc++, for example by adding /usr/local/gcc-5.4.0/lib64 to /etc/ld.so.conf, or using -Wl,-rpath /usr/local/gcc-5.4.0/lib64.

这篇关于_GLIBCXX_USE_CXX11_ABI,兼容GCC 4.8和ABI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆