使用自定义构建的 gcc 时程序链接失败 [英] program linking fails when using custom built gcc

查看:16
本文介绍了使用自定义构建的 gcc 时程序链接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个 Fedora 21 发行版,其中默认的 gcc 是 4.9.我在/usr/local/gcc48 中有一个定制的 gcc/g++ 4.8(例如,cuda 需要 gcc =< 4.8,我使用 update-alternatives 来选择这个)到目前为止,我一直在用这个 4.8 版本编译一些小程序,没有问题.

I'm running a fedora 21 distribution, in which the default gcc is 4.9. I have a custom built gcc/g++ 4.8 in /usr/local/gcc48 (for instance, cuda requires gcc =< 4.8, and i use update-alternatives to chose this one) I have been compiling a few small programs with this version 4.8 without problem so far.

现在,我得到了一个使用 vtk 库和其他库的源代码.如果我使用默认的 gcc 4.9,cmake 并使其正常工作.但是,当使用 gcc48 时,我得到:

Now, I have been given a source code which makes uses of vtk libraries and others. If I use default gcc 4.9, cmake and make work fine. However, when using gcc48, I get:

/usr/lib64/vtk/libvtkCommonDataModel.so.1: référence indéfinie vers « std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20 »
/lib64/libicuuc.so.52: référence indéfinie vers « __cxa_throw_bad_array_new_length@CXXABI_1.3.8 »
collect2: erreur: ld a retourné 1 code d'état d'exécution
CMakeFiles/main.dir/build.make:365: recipe for target '../bin/main'   failed
make[2]: *** [../bin/main] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/main.dir/all' failed
make[1]: *** [CMakeFiles/main.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2

我知道这是链接器错误,我试图指向 LD_LIBRARY_PATH=/usr/local/gcc48/lib 或 LD_LIBRARY_PATH=/usr/local/gcc48/lib64,但我卡住了.

I understand that is it a linker error, I tried to point LD_LIBRARY_PATH=/usr/local/gcc48/lib or LD_LIBRARY_PATH=/usr/local/gcc48/lib64, but i'm stuck.

这里有什么问题?

谢谢

推荐答案

__cxa_throw_bad_array_new_lengthGCC 4.9 中添加.这就是 @CXXABI_1.3.8 版本后缀的含义.您可以在此处查找这些版本代码:https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html

__cxa_throw_bad_array_new_length was added in GCC 4.9. That's what the @CXXABI_1.3.8 version suffix means. You can look up those version codes here: https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html

此错误表示您正在尝试将由 GCC 4.9 或更高版本编译的目标文件 /usr/lib64/vtk/libvtkCommonDataModel.so.1libstdc++.solibsupc++.so 来自 GCC 4.8 或更早版本.使用 GCC 4.8 重新构建 libvtkCommonDataModel.so,或者链接到正确的 libstdc++.so.

This error means that you are trying to link an object file /usr/lib64/vtk/libvtkCommonDataModel.so.1 compiled by GCC 4.9 or later with libstdc++.so or libsupc++.so from GCC 4.8 or earlier. Either rebuild libvtkCommonDataModel.so with GCC 4.8, or link against the correct libstdc++.so.

实际上,如果您想使用较新版本的 GCC 进行编译,但使用较旧的 libstdc++.so 运行,则可以这样做.

Actually, if you want to compile with a newer version of GCC but run with an older libstdc++.so, that can be done.

  1. 如果您想使用 GCC 5+ 编译并使用旧 GCC 的 libstdc++.so 运行,请使用 -D_GLIBCXX_USE_CXX11_ABI=0 编译.请参阅 https://bugzilla.mozilla.org/show_bug.cgi?id=1153109使用双 ABI 在 libstdc++ 手册中.

  1. Compile with -D_GLIBCXX_USE_CXX11_ABI=0 if you want to compile with GCC 5+ and run with libstdc++.so from older GCC. See https://bugzilla.mozilla.org/show_bug.cgi?id=1153109 and Using dual ABI in the libstdc++ manual.

链接到 stdc++compat.cpp 包含来自 Mozilla 的反向兼容黑客.你也可以看看我的 修改版,它不依赖于任何 Mozilla 头文件,但它有点过时了.特别是,它定义了一个存根 __cxa_throw_bad_array_new_length.

Link against stdc++compat.cpp containing back-compat hacks from Mozilla. You can also take a look at my modified version which doesn't depend on any Mozilla headers, but it's slightly out of date. In particular, this defines a stub __cxa_throw_bad_array_new_length.

这篇关于使用自定义构建的 gcc 时程序链接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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