Upgrading GCC/zh-cn

本文档将指导用户完成GCC的升级.

介绍
这篇文章讲述 升级 GCC. GCC降级可能会有不愿看到的副作用. 对于一些报告中常见的问题请查阅故障排除一节.

下一节将给出GCC升级的快速指南（这件事太容易了）. 如果你想要阅读升级GCC背后冗长的材料，请继续阅读GCC升级详解.

简明版
如果你正在升级GCC，那么你需要做的事情只有改变编译器版本和重新构建libtool.

如果你从GCC 3.4.0（3.x系列）或4.1之前的版本升级，你还需要运行 ：

检查当前版本并卸载旧版本

这样就完成了！

介绍
GCC升级向来一直都被神秘化了，从“建议你不需要再做任何事情”到“你需要重新编译你的整个系统”. 这些FUD（惧、惑、疑）大多数都源自用户对ABI不兼容性的不够了解. 首先先关注下libtool.

libtool 和 fix_libtool_files.sh
早前在 Gentoo 上安装 GCC 需要你运行一个叫  的特定命令. 一段时间之后，安装包（通过 toolchain eclass）集成了自动执行这个命令，因此用户不需要再手动执行.

在升级 gcc 版本之后我们需要重新编译 libtool 的原因在于它的主要目的：“libtool” 是一个工具集，通过一个通用的接口聚合了特定平台的代码，允许应用程序使用共享库进行构建，无需应对平台相关的共享库. 为能正确实现这一功能， 脚本使用的各种库的定位都包含了 GCC 版本硬编码信息.

ABI 变化
ABI（应用程序二进制接口）是一个所有处理二进制的程序（包括编译器、汇编器、链接器和语言运行库支持）都会使用的接口（来源：GCC 二进制兼容性）. 当二进制程序和库使用的 ABI 改变了之后，你将面临 链接错误或者程序错误的风险，除非你重新编译了所有的使用 C++ 代码的库. 是的，C++，因为多数的不兼容发生自 C++ ABI. 这也是为什么我们使用  命令更新   库.

那么为什么只有升级到GCC 3.4.0/4.1版本才需要这么做？这是因为在这之前的版本，GCC采用向下兼容的ABI，这使得你不需要重新编译软件和系统库. 当然，我们不能永远保证这种兼容性. 如果发生不兼容的情况， 库将很可能也会升级到更高的版本.

重新编译所有包

Some people swear that they need to rebuild every single package on their system when a new GCC version is made available. Of course, that doesn't make sense, since there are many applications that are not using GCC for their build and install process anyhow, so they would never be affected by such changes.

That however doesn't mean they are completely incorrect: newer GCC versions often include better support for the processors' instruction set, which might influence the performance of some applications in a positive way. Although it is expected that this improvement is generally only marginally, in some cases (especially CPU intensive applications) this might yield notable improvements.

There are also known cases where packages need to be built with the same compiler. Although these packages are usually bumped by Gentoo simultaneously (so that they are always built with the same GCC version) cherry-picking re-installs on these packages might prove to be troublesome. The various packages are a nice example on this matter.

libstdc++.so.6: version `GLIBCXX_3.4.15' not found
During updates, you might encounter an error like the following:

This means that you are trying to build a package with an older GCC version than with which some depending libraries were built. Remember when we told that the C++ ABI is forward-compatible? That is true, but it ensures only that higher (or same) GCC versions can be used when building applications and linking libraries (compared to the GCC version used to build those libraries).

To rebuild all the packages depending on libstdc++ the next bash script can be executed.

Which packages are known to need a rebuild?
The following table gives the packages that, if installed, need to be rebuild and why.