如何更改 Ubuntu 中的默认 GCC 编译器?
我已经在已经有 gcc/g++-4.4 的 ubuntu 11.04 上安装了 gcc-3.3/g++-3.3.所以在我的系统中,gcc-3.3 和 4.4 都可用.我可以根据需要调用两个编译器.如果我只是调用命令 gcc
然后 gcc-4.4 将被调用.要调用 gcc-3.3,我必须使用命令 gcc-3.3
.
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
.
如何将默认编译器更改为 gcc-3.3?当我执行命令 gcc
时,它应该调用 gcc-3.3 而不是 gcc-4.4.
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.
另外,如何将 make 文件中的变量 CXX 更改为 gcc-3.3?我希望更改系统中的一个公共全局位置,而不是更改所有 make 文件.
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.
正如@Tommy 建议的那样,你应该使用 update-alternatives
.
它为一个系列的每个软件分配值,以便定义调用应用程序的顺序.
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.
用于在系统上维护同一软件的不同版本.在您的情况下,您将能够使用 gcc
的多个偏角,并且一个偏角会受到青睐.
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.
要确定 gcc 当前的优先级,请输入@tripleee 评论指出的命令:
To figure out the current priorities of gcc, type in the command pointed out by @tripleee's comment:
update-alternatives --query gcc
现在,请注意归因于 gcc-4.4
的优先级,因为您需要为 gcc-3.3
赋予更高的优先级.
要设置你的替代方案,你应该有这样的东西(假设你的 gcc
安装位于 /usr/bin/gcc-3.3
和 gcc-4.4
的优先级小于50):
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
--编辑--
最后,您还可以使用update-alternatives
的交互界面,轻松切换版本.输入 update-alternatives --config gcc
要求在安装的 gcc 版本中选择你想使用的 gcc 版本.
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.
--编辑 2 --
现在,要在系统范围内修复 CXX 环境变量,您需要将 @DipSwitch 指示的行放在您的 .bashrc
文件中(这将仅对您的用户应用更改,这样更安全)我的意见):
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