如何在Ubuntu中更改默认的GCC编译器? [英] How to change the default GCC compiler in Ubuntu?

查看:539
本文介绍了如何在Ubuntu中更改默认的GCC编译器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在ubuntu 11.04上安装了gcc-3.3 / g ++ - 3.3,它已经有了gcc / g ++ - 4.4。所以在我的系统中,gcc-3.3和4.4都可用。我可以根据需要调用两个编译器。如果我只是调用命令 gcc ,那么gcc-4.4会被调用。要调用gcc-3.3,我必须使用命令 gcc-3.3

如何将默认编译器更改为gcc-3.3?当我执行命令 gcc 时,它应该调用gcc-3.3而不是gcc-4.4。

另外,我如何将make文件中的变量CXX更改为gcc-3.3?我希望在系统中更改一个通用的全局位置,而不是更改所有的make文件。

正如@Tommy所建议的,您应该使用 update-alternatives

它将值分配给系列中的每个软件,以便定义应用程序的调用顺序。


它用于在系统上维护同一软件的不同版本。在你的情况下,你将能够使用 gcc 的一些缩写,并且一个将会受到欢迎。



找出gcc的当前优先级,键入@tripee的评论指出的命令:

  update-alternatives --query gcc 

现在,请注意归因于 gcc-4.4 gcc-3.3

要设置你的选择,你应该有这样的(假设你的 gcc 安装位于 /usr/bin/gcc-3.3 gcc-4.4 的优先级小于50)

  update-替代品--install / usr / bin / gcc gcc /usr/bin/gcc-3.3 50 

- edit -



最后,您还可以使用 update-alternatives 轻松切换不同的版本。输入 update-alternatives --config gcc 以选择要安装的gcc版本。



<编辑2 -



现在,要修复系统范围内的CXX环境变​​量,您需要将@ DipSwitch所指示的行在你的 .bashrc 文件中(这将只适用于你的用户,这在我看来更安全):

  echo'export CXX = / usr / bin / gcc-3.3'>> 〜/ .bashrc 


I have installed gcc-3.3/g++-3.3 on ubuntu 11.04 which already has gcc/g++-4.4. So in my system both gcc-3.3 and 4.4 are available. I am able to call both compilers as I want. If I just call the command gcc then gcc-4.4 will get called. To call gcc-3.3, I have to use the command gcc-3.3.

How can I change the default compiler as gcc-3.3? When I execute the command gcc it should call the gcc-3.3 and not gcc-4.4.

In addition, how can I change the variable CXX in a make file to gcc-3.3? I wish to change one common global place in the system instead of changing all make files.

解决方案

As @Tommy suggested, you should use update-alternatives.
It assigns values to every software of a family, so that it defines the order in which the applications will be called.

It is used to maintain different versions of the same software on a system. In your case, you will be able to use several declinations of gcc, and one will be favoured.

To figure out the current priorities of gcc, type in the command pointed out by @tripleee's comment:

update-alternatives --query gcc

Now, note the priority attributed to gcc-4.4 because you'll need to give a higher one to gcc-3.3.
To set your alternatives, you should have something like this (assuming your gcc installation is located at /usr/bin/gcc-3.3, and gcc-4.4's priority is less than 50):

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-3.3 50

--edit--

Finally, you can also use the interactive interface of update-alternatives to easily switch between versions. Type update-alternatives --config gcc to be asked to choose the gcc version you want to use among those installed.

--edit 2 --

Now, to fix the CXX environment variable systemwide, you need to put the line indicated by @DipSwitch's in your .bashrc file (this will apply the change only for your user, which is safer in my opinion):

echo 'export CXX=/usr/bin/gcc-3.3' >> ~/.bashrc

这篇关于如何在Ubuntu中更改默认的GCC编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆