本文介绍了在Mac OS X上将GCC版本更改为4.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OS X上,我目前安装了几个gcc版本的gcc。每当我使用 gcc -v g ++ -v ,它告诉我: gcc version 4.2 0.1 。不过,为了利用C ++ 11,我安装了gcc 4.7。编辑:我有自制软件,而不是macports。

$ b $我如何改变它,以便gcc / g ++指向4.7而不是4.2.1?

解决方案

整蛊的问题,如果我们不知道其他安装的完整路径。但基本上,您可以更改本地用户 .profile 设置中的$ PATH命令。假设你的4.7安装位于 / usr / local / bin / &我们知道Apple的默认版本位于 / usr / bin / 然后编辑您的 .profile so / usr / local / bin / 出现在$ PATH命令中的 / usr / bin / 之前。



默认应该是这样的:

调整应该是这样的:

有一种方法可以强制所有用户在系统范围内进行此更改,但我不建议这样做。不要用苹果实现一个* nix环境的更深层次,而且往往是非标准的方式。将它保留在用户本地。



编辑: ,看看提供的解决方案是否可以帮助你。它看起来像通过MacPorts安装 gcc_select 将是最干净的解决方案。


On OS X, I currently have a couple versions of gcc installed. Whenever I use gcc -v or g++ -v, it tells me: gcc version 4.2.1. I have installed gcc 4.7, though, in the interest of taking advantage of C++11. How can I change it so that gcc/g++ points to 4.7 instead of 4.2.1?

EDIT: I have homebrew, not macports.

解决方案

Tricky question if we don’t know the full path of the other installs. But basically you could change the $PATH order in your local user .profile settings. So let’s say your 4.7 install is in /usr/local/bin/ & we know the Apple default version is in /usr/bin/ then edit your .profile so /usr/local/bin/ comes before /usr/bin/ in $PATH order.

Default should be something like this:

Adjusted should be something like this:

There is a way to force this change systemwide for all users, but I do not recommend that. Don’t muck around with the deeper—and often non-standard—ways Apple implements a *nix environment. Keep it local to your user.

EDIT: Check the discussion here to see if any solutions offered can help you. It does seem like installing gcc_select via MacPorts would be the cleanest solution.

这篇关于在Mac OS X上将GCC版本更改为4.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 01:35