AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 770358
Accepted
Steve Lorimer
Steve Lorimer
Asked: 2016-05-11 09:03:37 +0800 CST2016-05-11 09:03:37 +0800 CST 2016-05-11 09:03:37 +0800 CST

我应该如何处理 gcc-4.9 和 gcc-5 之间的 ABI 不兼容问题?

  • 772

我最近将我的开发机器升级到 Ubuntu 16.04(全新安装,擦除 14.04)

gcc 的默认版本是gcc-5.3.1.

我遇到的一个问题是供应商提供的库仅使用 gcc-4.9 构建,它与 gcc-5 不兼容。

我已要求供应商提供该库的新版本,但短期内不太可能发生这种情况。

与此同时,我已经gcc-4.9.3从 Ubuntu 的软件包仓库安装了。

我现在安装了 gcc-4.9 和 gcc-5:

ls -l /usr/bin/gcc*
lrwxrwxrwx 1 root root      5 May  9 11:49 /usr/bin/gcc -> gcc-5
-rwxr-xr-x 1 root root 838008 Apr 13 23:23 /usr/bin/gcc-4.9
-rwxr-xr-x 1 root root 915704 Apr 13 11:29 /usr/bin/gcc-5

我尝试使用 gcc-4.9 构建我们的源代码,但现在我遇到了相同的 ABI 问题,但方向相反。

我遇到的问题是我们有一堆依赖项,我们通常会从发行版包中安装这些依赖项

sudo apt-get install \
    python-dev \
    libbz2-dev \
    libboost-all-dev \
    libprotobuf-dev \
    libgoogle-perftools-dev \
    postgresql \
    libpqxx-dev

虽然我可以将我的构建配置为使用 gcc-4.9

mkdir build && cd build
CC=/usr/bin/gcc-4.9 CXX=/usr/bin/g++-4.9 cmake ..
make -j8

我现在在链接时遇到链接器错误libtcmalloc_minimal.a,libprotobuf.a等等。

因此,我尝试的下一步是删除从发行版存储库中安装的所有依赖项,并开始从源代码构建依赖项。

CC=/usr/bin/gcc-4.9 CXX=/usr/bin/g++-4.9 ./configure
make -j8
sudo make install

这里的问题是我开始陷入困境。每个依赖项都有其他依赖项,我不确定它会在哪里结束。

另一种选择是降级回 Ubuntu 14.04 或带有 gcc-4.9 而不是 gcc-5 的某些版本。

在我尝试这个 thurmonuclear 选项之前,我想知道是否有更好的方法来做到这一点?

也许可以从使用 gcc-4.9 或其他方式构建的 repos 安装?

14.04
  • 3 3 个回答
  • 11726 Views

3 个回答

  • Voted
  1. Best Answer
    Yttrill
    2016-09-14T01:52:32+08:002016-09-14T01:52:32+08:00

    您遇到的问题与需要 C++ 字符串(和列表)类型的不同实现的 C++11 标准有关。为了兼容性,g++5.2及以上默认编译新的C++11兼容类型,(无论是否指定-std=c++11),但可以设置宏

    -D_GLIBCXX_USE_CXX11_ABI=0
    

    恢复到旧的 C++ 字符串类型。新的 libstdc++ 实现包含两个ABI。因此,如果您有必须与旧的不兼容 ABI 链接的二进制文件,则必须在 g++ 编译中设置上述宏。这应该会生成与旧 ABI 兼容的二进制文件。

    不幸的是,如果您使用的是操作系统中的库而不是 C++ 标准库,那么除非这些库是多架构的,因为它们在两个ABI 中都提供了与 ABI 不同的所有功能,那么您就搞砸了,因为它们可能只会拥有新的 ABI。

    话虽如此,我在旧 Ubuntu 上下载不受信任的现代 g++ 时遇到问题,它只是拒绝生成新的 ABI。因此,似乎 backport fromppa:ubuntu-toolchain-r/test实际上被严重破坏了,因为它拒绝根据新的 ABI 生成二进制文件。

    无论如何,当您将所有内容链接在一起时,底线必须是旧 ABI 或新 ABI。以下将告诉您正在使用哪个:

    g++ --version
    echo '#include <string>' > test.cpp
    echo 'void f(std::string s) {}' >> test.cpp
    cat test.cpp
    g++ -std=gnu++11 -c -o test.o test.cpp
    nm test.o | c++filt
    

    如果有

    std::basic_string<char, ....
    

    在其中,它是旧的ABI。如果有

    std::__cxx11::basic_string<char, ...
    

    其中,它是新的ABI。

    • 9
  2. Eofla
    2016-05-11T09:07:25+08:002016-05-11T09:07:25+08:00

    按:转到 tty1:CTRL+ALT+F1

    使用以下命令清除 gcc-5.3.1:

    sudo apt-get purge gcc-5.3.1*
    

    并使用以下命令安装 gcc-4.9.3:

    sudo apt-get install gcc-4.9.3
    

    注意:这需要互联网连接!

    • 0
  3. Y00
    2019-10-08T20:58:00+08:002019-10-08T20:58:00+08:00

    最好使用-D_GLIBCXX_USE_CXX11_ABI=0。但是你也可以使用g++的这个选项,甚至可以更好

           -fabi-version=n
               Use version n of the C++ ABI.  The default is version 0.
    
               Version 0 refers to the version conforming most closely to the C++ ABI specification.  Therefore, the ABI obtained using version 0 will change in different versions of G++ as ABI bugs are
               fixed.
    
               Version 1 is the version of the C++ ABI that first appeared in G++ 3.2.
    
               Version 2 is the version of the C++ ABI that first appeared in G++ 3.4, and was the default through G++ 4.9.
    
               Version 3 corrects an error in mangling a constant address as a template argument.
    
               Version 4, which first appeared in G++ 4.5, implements a standard mangling for vector types.
    
               Version 5, which first appeared in G++ 4.6, corrects the mangling of attribute const/volatile on function pointer types, decltype of a plain decl, and use of a function parameter in the
               declaration of another parameter.
    
               Version 6, which first appeared in G++ 4.7, corrects the promotion behavior of C++11 scoped enums and the mangling of template argument packs, const/static_cast, prefix ++ and --, and a class
               scope function used as a template argument.
    
               Version 7, which first appeared in G++ 4.8, that treats nullptr_t as a builtin type and corrects the mangling of lambdas in default argument scope.
    
               Version 8, which first appeared in G++ 4.9, corrects the substitution behavior of function types with function-cv-qualifiers.
    
               Version 9, which first appeared in G++ 5.2, corrects the alignment of "nullptr_t".
    
               See also -Wabi.
    
           -fabi-compat-version=n
               On targets that support strong aliases, G++ works around mangling changes by creating an alias with the correct mangled name when defining a symbol with an incorrect mangled name.  This switch
               specifies which ABI version to use for the alias.
    
               With -fabi-version=0 (the default), this defaults to 2.  If another ABI version is explicitly selected, this defaults to 0.
    
               The compatibility version is also set by -Wabi=n.
    
    
    • 0

相关问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve