https://wiki.gentoo.org/wiki/Upgrading_GCC/zh-cn#.E4.BB.8B.E7.BB.8D
本文檔将指導使用者完成GCC的更新。
Contents
[hide]
1 快速開始
1.1 介紹
1.2 Short version
2 GCC upgrading explained
2.1 介紹
2.2 libtool 和 fix_libtool_files.sh
2.3 ABI changes
2.3.1 The special case C++11 (and C++14)
2.4 Rebuilding everything
3 故障排除
3.1 libstdc++.so.6: version `GLIBCXX_3.4.15’ not found
3.2 那些包是已知的要重新建構的?
4 另請參閱
快速開始
介紹
這篇文章講述 更新 GCC。GCC降級可能會有不願看到的副作用。對于一些報告中常見的問題請查閱故障排除一節。
下一節将給出GCC更新的快速指南(這件事太容易了)。如果你想要閱讀更新GCC背後冗長的材料,請繼續閱讀GCC更新詳解。
Short version
如果你正在更新GCC,那麼你需要做的事情隻有改變編譯器版本和重新建構libtool。
root #emerge -u sys-devel/gcc
root #gcc-config -l
[1] i686-pc-linux-gnu-4.4.5 *
[2] i686-pc-linux-gnu-4.5.3
root #gcc-config 2
root #env-update && source /etc/profile
root #emerge –oneshot libtool
If you upgrade GCC from a version earlier than 3.4.0 (for the 3.x series) or 4.1, you will need to run revdep-rebuild as well:
root #revdep-rebuild –library ‘libstdc++.so.5’
檢查目前版本并解除安裝舊版本
root #gcc –version
root #emerge -C =sys-devel/gcc-4.4.5
這樣就完成了!
GCC upgrading explained
介紹
GCC upgrading has always been mystified, with suggestions ranging from “You do not need to do anything” up to “You will need to rebuild your entire system twice”. Most of this FUD comes from the confusion surrounding ABI incompatibility. But first a quick pointer towards libtool.
libtool 和 fix_libtool_files.sh
早前在 Gentoo 上安裝 GCC 需要你運作一個叫 fix_libtool_files.sh 的特定指令。一段時間之後,安裝包(通過 toolchain eclass)內建了自動執行這個指令,是以使用者不需要再手動執行。
The reason we need to rebuild libtool after the upgrade of gcc versions is because of its main purpose: libtool is a toolset that aggregates platform-specific code in a generic interface, allowing applications to build against shared libraries without needing to deal with the platform specific aspects of shared libraries. To fulfill its function properly, the libtool script uses various library locations that have hard-coded gcc version information in them.
ABI changes
ABI應用程式二進制接口是一個所有處理二進制的程式(包括編譯器、彙編器、連結器和語言運作庫支援)都會使用的接口(來源:GCC 二進制相容性)。當二進制程式和庫使用的 ABI 改變了之後,你将面臨 連結錯誤或者程式錯誤的風險,除非你重新編譯了所有的使用 C++ 代碼的庫。
Yes, C++, since most incompatibilities occur within the C++ ABI. If you are upgrading to GCC 4.1, or GCC 5.1, you would probably encounter ABI issues. This is also why we use the revdep-rebuild command against the libstdc++.so.5 (from GCC 3 to GCC 4.1), or libstdc++.so.6 (from GCC 4 to GCC 5.1).
root #revdep-rebuild –library ‘libstdc++.so.6’ – –exclude gcc
那麼為什麼隻有更新到GCC 3.4.0/4.1/5.1版本才需要這麼做?這是因為在這之前的版本,GCC采用向下相容的ABI,這使得你不需要重新編譯軟體和系統庫。當然,我們不能永遠保證這種相容性。如果發生不相容的情況,libstdc++.so 庫将很可能也會更新到更高的版本。
The special case C++11 (and C++14)
While GCC (or more specifically, libstdc++) goes to great lengths to guarantee stability of the ABI, this guarantee does not extend to all parts of C++ within libstdc++. Formally, with versions starting from 3.4, GCC/libstdc++ only guarantees C++98/C++03 ABI stability and not more. This is crucial for packages that depend on C++11. GCC only makes C++11 ABI stability guarantees beginning with version 5.1. This means that switching (even minor) versions of gcc (say from 4.7.3 -> 4.7.4) might cause ABI breakage for binaries built from C++11 code.
For more information and some examples, see:
https://bugs.gentoo.org/show_bug.cgi?id=513386
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61758
https://blogs.gentoo.org/blueness/2015/03/10/the-c11-abi-incompatibility-problem-in-gentoo/
http://stackoverflow.com/a/16196475
Rebuilding everything
一些人認為當新版本的GCC安裝好之後,他們需要重新編譯他們系統上的已經安裝過的應用,當然,這被認為是沒有意義的,因為這裡有很多應用在編譯和建構的時候并沒有用到GCC,是以更新不會影響到它們.
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 marginal, 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 qt-* packages are a nice example on this matter.
故障排除
libstdc++.so.6: version
GLIBCXX_3.4.15' not found
在更新過程中,你或許會遇到以下面這些錯誤:
CODE GLIBCXX_x.y.z not found
cmake_bootstrap_28021_test: /usr/lib/gcc/i486-pc-linux-gnu/4.1.2/libstdc++.so.6:
version
GLIBCXX_3.4.11’ not found
這意味着你正在用一個”較老版本”(新版本指的是那些已經建構好這些依賴庫的版本)的GCC來建構這些包.請記住所謂的C++ABI 向前相容指的是:假設你可以用某個版本的GCC成功建構程式和連接配接庫檔案,那麼你可以用比這個版本更高版本GCC去建構這些程式,而不是用更低版本GCC來建構這些程式.
To rebuild all the packages depending on libstdc++, see the previous revdep-rebuild section.