简体   繁体   English

强制G ++(GCC)到特定的libstdc ++版本(GLIBCXX_ *)

[英]Forcing G++ (GCC) to a specific libstdc++ version (GLIBCXX_*)

I'm trying to build a binary with GCC 4.9.0 that is backwards-compatible against libstdc++ . 我正在尝试使用GCC 4.9.0构建一个与libstdc++向后兼容的二进制文件。 According to GCC's ABI Policy and Guidelines and Options Controlling C++ Dialect , the command line option -fabi-version should do the trick; 根据GCC的ABI策略和指南以及控制C ++方言的选项,命令行选项-fabi-version应该可以解决问题; however, no matter which version I set, I still get imports of symbols from a version newer then desired, like this: 但是,无论我设置哪个版本,我仍然可以从更新的版本导入符号,如下所示:

$ objdump -T binary | grep GLIBCXX_3.4.20
00000000      DF *UND*  00000000  GLIBCXX_3.4.20 _ZSt24__throw_out_of_range_fmtPKcz

I've tried -fabi-version=1 to -fabi-version=5 (ABI version 5 corresponds to GCC 4.6, which is guaranteed to be present on the target system), but those imports keep winding up in the resulting files. 我已经尝试-fabi-version=1-fabi-version=5 (ABI版本5对应于GCC 4.6,它保证存在于目标系统上),但是这些导入会在结果文件中逐渐-fabi-version=5

How do I fix this? 我该如何解决? Going back to an old GCC version is not an option to me for other reasons. 由于其他原因,回到旧的GCC版本不是我的选择。

the command line option -fabi-version should do the trick 命令行选项-fabi-version应该可以解决问题

No, that's completely unrelated to what you want. 不,这与你想要的完全无关。 That option affects the code generated by the compiler, it does not mean you can link to an older version of libstdc++ (which is what you would need in order to stop depending on symbols in the newer libstdc++). 该选项会影响编译器生成的代码,但这并不意味着您可以链接到旧版本的libstdc ++(这是为了根据较新的libstdc ++中的符号停止所需的)。

You cannot link to an older libstdc++ with a new GCC. 您无法使用新的GCC链接到较旧的libstdc ++。 The version of libstdc++ is tightly coupled to the version of GCC, so if you want to linker to an older libstdc++ then you need to compile with an older GCC. libstdc ++的版本与GCC的版本紧密耦合,因此如果要链接到较旧的libstdc ++,则需要使用较旧的GCC进行编译。

You cannot tell libstdc++ to not use the new symbols, the reason it depends on them is because it needs them. 你不能告诉libstdc ++不使用新符号,它依赖于它们的原因是因为它需要它们。 Use an older libstdc++. 使用较旧的libstdc ++。

Going back to an old GCC version is not an option to me for other reasons. 由于其他原因,回到旧的GCC版本不是我的选择。

Then you're screwed. 然后你被搞砸了。

You either need to use an older GCC, or not link dynamically to libstdc++.so . 您需要使用较旧的GCC,或者不能动态链接到libstdc++.so

On Red Hat Enterprise Linux or CentOS you would have the option of using a newer GCC from the Developer Toolset which avoids linking to the new libstdc++.so but that is only compatible with the system GCC, which is GCC 4.4 for RHEL6 or GCC 4.7 for RHEL7. 在Red Hat Enterprise Linux或CentOS上,您可以选择使用Developer Toolset中较新的GCC,避免链接到新的libstdc++.so只能与系统GCC兼容,GCC 4.4适用于RHEL6或GCC 4.7适用于RHEL7。 You can't use it to be compatible with GCC 4.6. 您不能使用它与GCC 4.6兼容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM