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?
在OS X上,我现在安装了几个版本的gcc。每当我使用gcc -v或g++ -v时,它告诉我:gcc版本4.2.1。不过,为了利用c++ 11的优势,我已经安装了gcc 4.7。我怎样才能改变它,使gcc/g+点变成4.7而不是4.2.1?
EDIT: I have homebrew, not macports.
编辑:我有自制的,不是macports。
3 个解决方案
#1
6
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.
如果我们不知道其他安装的完整路径,就会遇到棘手的问题。但基本上你可以改变本地用户的$PATH顺序。假设你的4.7安装在/usr/local/bin/ &我们知道苹果默认的版本在/usr/bin/然后编辑你的.profile So /usr/local/bin/在$PATH订单中出现。
Default should be something like this:
违约应该是这样的:
export PATH=/usr/bin:/usr/local/bin:[etc, etc, etc]
导出路径= / usr / bin:/ usr /地方/ bin:(等等,等等)
Adjusted should be something like this:
调整后应该是这样的:
export PATH=/usr/local/bin:/usr/bin:[etc, etc, etc]
导出路径= / usr /地方/ bin:/ usr / bin:(等等,等等)
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.
有一种方法可以让所有用户都使用这个变更系统,但我不建议这样做。不要用苹果公司实现一个*nix环境的更深层和非标准的方式来解决问题。让它本地的你的用户。
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.
编辑:查看这里的讨论,看看是否有任何解决方案可以帮助您。看起来,通过MacPorts安装gcc_select将是最干净的解决方案。
#2
7
I think you can do something like this. Go to /usr/bin
我认为你可以做这样的事情。去工作
Assume you have install the gcc-4.7
using home brew in mavericks. then type:
假设您在mavericks中使用home brew安装gcc-4.7。然后输入:
cd /usr/bin
sudo mv gcc gcc_mavs
sudo ln -s /usr/local/Cellar/gcc48/4.7.0/bin/gcc-4.7 gcc
After this type to verify if you have select the right gcc compiler.
在此类型之后,验证您是否选择了正确的gcc编译器。
gcc -v
gcc - v
#3
0
I found a very good tutorial online. Although, it is a little bit older (describes the process for gcc 3.2) the same general approach can still be used http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/install_gcc.html
我在网上找到了一个很好的教程。虽然,它有点旧(描述了gcc 3.2的过程),但是仍然可以使用相同的通用方法。
#1
6
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.
如果我们不知道其他安装的完整路径,就会遇到棘手的问题。但基本上你可以改变本地用户的$PATH顺序。假设你的4.7安装在/usr/local/bin/ &我们知道苹果默认的版本在/usr/bin/然后编辑你的.profile So /usr/local/bin/在$PATH订单中出现。
Default should be something like this:
违约应该是这样的:
export PATH=/usr/bin:/usr/local/bin:[etc, etc, etc]
导出路径= / usr / bin:/ usr /地方/ bin:(等等,等等)
Adjusted should be something like this:
调整后应该是这样的:
export PATH=/usr/local/bin:/usr/bin:[etc, etc, etc]
导出路径= / usr /地方/ bin:/ usr / bin:(等等,等等)
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.
有一种方法可以让所有用户都使用这个变更系统,但我不建议这样做。不要用苹果公司实现一个*nix环境的更深层和非标准的方式来解决问题。让它本地的你的用户。
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.
编辑:查看这里的讨论,看看是否有任何解决方案可以帮助您。看起来,通过MacPorts安装gcc_select将是最干净的解决方案。
#2
7
I think you can do something like this. Go to /usr/bin
我认为你可以做这样的事情。去工作
Assume you have install the gcc-4.7
using home brew in mavericks. then type:
假设您在mavericks中使用home brew安装gcc-4.7。然后输入:
cd /usr/bin
sudo mv gcc gcc_mavs
sudo ln -s /usr/local/Cellar/gcc48/4.7.0/bin/gcc-4.7 gcc
After this type to verify if you have select the right gcc compiler.
在此类型之后,验证您是否选择了正确的gcc编译器。
gcc -v
gcc - v
#3
0
I found a very good tutorial online. Although, it is a little bit older (describes the process for gcc 3.2) the same general approach can still be used http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/install_gcc.html
我在网上找到了一个很好的教程。虽然,它有点旧(描述了gcc 3.2的过程),但是仍然可以使用相同的通用方法。