问题描述
一个简单的问题 - 有没有办法让 g ++
链接器与特定的 libstdc ++
库版本链接?在 gcc
/ g ++
的手册页中,我没有找到任何有用的东西,在这里的其他问题中都没有。
以下是情况 - 我的应用程序使用了一个特定的共享库,它由 libstdc ++。so.5
和I想要在 RHEL5
上安装和使用它。因此,当我尝试在 RHEL5
机器上构建应用程序时,我收到了警告:
警告:libstdc ++。so.5,..the_shared_library_所需要的可能与libstdc ++冲突so.6
安装 compat-libstdc ++
rpm没有帮助,程序在 std :: string
,因为不能 。所以,在这个 RHEL5
机器上,我有这个:
[root @ xxx]#ll / usr / lib / libstd *
-rwxr-xr-x 1 root root 259532 Aug 21 2006 /usr/lib/libstdc++-3-libc6.2-2-2.10.0.so
lrwxrwxrwx 1 root root 31 Jul 28 19:35 /usr/lib/libstdc++-libc6.2-2.so.3 - > libstdc ++ - 3-libc6.2-2-2.10.0.so
lrwxrwxrwx 1 root root 18 Aug 24 15:08 /usr/lib/libstdc++.so.5 - > libstdc ++。so.5.0.7
-rwxr-xr-x 1 root root 733456 Aug 21 2006 /usr/lib/libstdc++.so.5.0.7
以及当我制作时
[root @ xxxx]#ldd my_exe
libstdc ++。so.6 => /usr/lib/libstdc++.so.6(0x00333000)
...
libstdc ++。so.5 => /usr/lib/libstdc++.so.5(0x00ddf000)
这是坏的,因为我知道它是未定义的行为:/ b / b
那么,有什么方法可以使用 libstdc ++。so.5
来构建我的可执行文件吗? (删除 libstdc ++。so.6
不是一个选项,因为很多原因,静态链接也不是一个选项)。
非常感谢!
以下是; g ++开关的默认值从1变为2,同时g ++引入了3.4中的libstdc ++。so.6。这意味着要链接到较旧的libstdc ++库,您需要
- 查找并使用等效的C ++头文件而不是您的编译器
- 使用
-fabi-version = 1
重新编译所有代码(以及任何其他正在使用的C ++库) >
否则您将面临ABI不兼容的风险。我无法准确告诉你所做的修改是什么,但总的来说,最好尝试使用相同的编译器版本来保存所有已编译的C ++代码。
假设你不喜欢我想你有两个选择:
- 请你的共享库供应商重新编译库你的GCC版本。这可能不是微不足道的,因为g ++ 3.4引入了一个新的更严格的C ++解析器。
- 问你的供应商他们用什么版本的g ++首先编译库并使用该版本编译你的自己的代码。 RH可能会提供compat-gcc编译器以及libstdc ++ - 我不记得了。但是,您还需要使用所有其他库和操作系统提供的C ++库的低级版本,因此可能最容易在具有正确编译器的旧版Red Hat版本的VM上进行编译。 >
A simple question - is there any way to make the g++
linker to link with a specific libstdc++
library version? I didn't find anything useful in the man page of gcc
/g++
, neither in other questions here.
Here's the situation - my application uses a specific shared library, that's built with libstdc++.so.5
and I want to install and use it on RHEL5
. So, when I try to build the application on a RHEL5
machine, I got the warning:
warning: libstdc++.so.5, needed by ..the_shared_library_.. may conflict with libstdc++.so.6
Installing a compat-libstdc++
rpm didn't help, the program crashes on a destructor of std::string
, because of the incapability. So, on this RHEL5
machine I have this:
[root@xxx]# ll /usr/lib/libstd*
-rwxr-xr-x 1 root root 259532 Aug 21 2006 /usr/lib/libstdc++-3-libc6.2-2-2.10.0.so
lrwxrwxrwx 1 root root 31 Jul 28 19:35 /usr/lib/libstdc++-libc6.2-2.so.3 -> libstdc++-3-libc6.2-2-2.10.0.so
lrwxrwxrwx 1 root root 18 Aug 24 15:08 /usr/lib/libstdc++.so.5 -> libstdc++.so.5.0.7
-rwxr-xr-x 1 root root 733456 Aug 21 2006 /usr/lib/libstdc++.so.5.0.7
and when I make
[root@xxxx]# ldd my_exe
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00333000)
...
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x00ddf000)
which is bad, as I know it's undefined behavior :/
So, is there any way to build my executable using only libstdc++.so.5
? (removing libstdc++.so.6
is not an option because of many reasons. Static linking is not an option, too ).
Thanks a lot!
Here's the ABI versions table; the default value for the -fabi-version
switch changed from 1 to 2 at the same time g++ introduced libstdc++.so.6 with 3.4. This means that to link against the older libstdc++ library you would need to
- find and use the equivalent C++ headers instead of the ones included with your compiler
- recompile all your code (and any other C++ libraries you're using) with
-fabi-version=1
otherwise you run the risk of ABI incompatibilities. I can't tell you precisely what the changes were but in general it's best to try and keep all C++ code you have compiled with the same compiler version.
Assuming you don't want to try and hack things togther like this I think you have two choices:
- ask your shared library vendor to recompile the library with your version of GCC for you. This may not be trivial as g++ 3.4 introduced a new stricter C++ parser.
- ask your vendor which version of g++ they used to compile the library in the first place and use that version to compile your own code. RH might provide a compat-gcc compiler as well as the libstdc++ - I can't remember. However you'll also need down-level versions of all other libraries and OS-provided C++ libraries that you're using, so might be easiest to compile on a VM with an older Red Hat version that had the right compiler.
这篇关于如何链接特定库(g ++; libstdc ++。so.5和libstdc ++。so.6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!