Linux 如何使用多个版本的 GCC

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/448457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 16:52:59  来源:igfitidea点击:

How to use multiple versions of GCC

c++linuxgccg++

提问by Alex

We have a new application that requires glibc 2.4 (from gcc 4.1). The machine we have runs on has gcc 3.4.6. We can not upgrade, and the application must be run on this machine.

我们有一个需要 glibc 2.4(来自 gcc 4.1)的新应用程序。我们运行的机器有 gcc 3.4.6。我们不能升级,应用程序必须在这台机器上运行。

We installed gcc 4.1, however, when it comes to compile time it is using all the includes, etc, from 3.4.6.

我们安装了 gcc 4.1,但是,在编译时它使用了 3.4.6 中的所有包含等。

How do we get around this?

我们如何解决这个问题?

Any suggestions on using 4.1 for just this application?

关于仅针对此应用程序使用 4.1 的任何建议?

采纳答案by nzpcmad

Refer "How to install multiple versions of GCC" herein the GNU GCC FAQ.

请参阅“如何安装GCC的多个版本”这里的GNU GCC FAQ。

There's also a white paper here.

还有一个白皮书这里

回答by Konrad Rudolph

Have you tried gcc-select? Otherwise, try setting the INCLUDE_PATHand LIBRARY_PATHin your shell.

你试过gcc-select吗?否则,请尝试在 shell 中设置INCLUDE_PATHLIBRARY_PATH

回答by Johannes Schaub - litb

You possibly still execute the old gcc. Try making a symlink from gccto your version of it, like

您可能仍然执行旧的 gcc。尝试从gcc它的版本创建符号链接,例如

ln -s gcc-4.1 gcc

Beware of not removing an old "gcc" binary placed there, in case they placed not just a symlink. If you can recompile your own gcc version, the safest is just use another prefix at configure time of gcc, something like --prefix=/home/jojo/usr/gcc(i did it that way with gcc-4.4 from svn-trunk, and it worked great).

请注意不要删除放置在那里的旧“gcc”二进制文件,以防它们放置的不仅仅是符号链接。如果您可以重新编译自己的 gcc 版本,最安全的方法是在 gcc 的配置时使用另一个前缀,例如--prefix=/home/jojo/usr/gcc(我使用 svn-trunk 的 gcc-4.4 这样做,并且效果很好)。

Note that that just runs the right gcc version. If you update your gcc, your glibc won't be updated automatically too. It's a separate package which is deeply coupled with the rest of the system. Be careful when installing another glibc version.

请注意,它只运行正确的 gcc 版本。如果您更新 gcc,您的 glibc 也不会自动更新。它是一个单独的包,与系统的其余部分深度耦合。安装另一个 glibc 版本时要小心。

回答by endian

update-alternatives is a very good way to have multiple gcc versions:

update-alternatives 是拥有多个 gcc 版本的好方法:

http://ubuntuguide.net/how-to-install-and-setup-gcc-4-1g4-1-in-ubuntu-10-0410-10

http://ubuntuguide.net/how-to-install-and-setup-gcc-4-1g4-1-in-ubuntu-10-0410-10

回答by i716

for Ubuntu it's pretty easy

对于 Ubuntu,这很容易

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

sudo apt-get update

sudo apt-get update

and then install for example gcc version 6

然后安装例如 gcc 版本 6

sudo apt-get install gcc-6

sudo apt-get install gcc-6