OSX - 用通过Homebrew安装的4.9替换gcc 4.2.1版本 [英] OSX - replace gcc version 4.2.1 with 4.9 installed via Homebrew

查看:3825
本文介绍了OSX - 用通过Homebrew安装的4.9替换gcc 4.2.1版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一直困扰我一段时间。我试图编译一个巨大的C ++文件(我知道它的工作原理我工作正常在我的Arch Linux计算机上工作)。当我在我的mac上检查我的GCC版本它返回以下

 配置:--prefix = / Applications / Xcode.app / contents / Developer / usr --with-gxx-include-dir = / usr / include / c ++ / 4.2.1 
Apple LLVM版本6.0(clang-600.0.57)(基于LLVM 3.5svn)
目标:x86_64-apple-darwin14.1.0
线程模型:posix

也安装了使用Homebrew的最新版本的GCC版本

  brew install gcc49 
pre>

我现在的问题是如何将新安装的GCC版本应用为终端使用的默认版本?



我也知道,当你使用自制程序isntall gcc它命名为gcc-49,以便包裹之间没有混淆。



我不知道如何用我安装的4.9版本替换XCode附带的4.2.1版本。



感谢



编辑:
切换到我的mac以获取gcc --version的完整返回语句



编辑2:
我的结束游戏是能够导航到目录并能够输入

  make 
sudo make install

安装已创建的守护程序。现在,随机包和标准库返回了大量的错误。

解决方案

默认情况下, homebrew 将其安装的软件包的可执行文件(二进制文件)放入 / usr / local / bin - 这对于本地用户安装的二进制文件来说是一个相当明智的地方当你考虑它 - 与 / bin 相比,它包含属于核心操作系统的标准化二进制文件。因此,您的 brew 命令应该已经将 gcc-4.9 安装到 / usr / local / bin 。现在的问题是如何使用它...您有几个选项。



选项1



如果你只是想编译一两个事情,今天和明天,然后可能不再使用编译器,你可以只是调用 gcc 安装 homebrew 使用以下完整路径:

  / usr / local /bin/gcc-4.9 --version 

选项2 >

如果你打算使用 gcc 相当多,每次都会显式地输入完整路径,因此您可以将以下内容放入您的〜/ .bash_profile

  PATH = / usr / local / bin:$ PATH 

,然后启动一个新的终端,它需要查看 / usr / local / bin ,这样你就可以简单地输入

  gcc-4.9 --version 

选项3



如果您只是想使用 gcc 来调用编译器,而不必担心实际版本,您可以执行上面的选项2,并另外创建一个象这样的符号链接

  cd / usr / local / bin 
ln -s gcc-4.9 gcc

这将允许您运行通过在命令行中键入 gcc ,可以

安装 gcc >

  gcc --version 


$ b b

注意:



如果您以后要安装,请说 gcc-4.13 或somesuch,您将像以前一样执行 brew install ,然后按如下方式更改符号链接:

  cd / usr / local / bin 
rm gcc#删除从gcc到gcc-4.9的旧链接
ln -s gcc-4.13 gcc#从gcc到gcc-4.13


This has been plaguing me for awhile now. I am trying to compile a huge C++ file (I know it works as I it works fine on my Arch Linux computer at work). When I checked my GCC version on my mac It returns the following

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix

I have also installed the most recent GCC version using Homebrew with

brew install gcc49

My question now is how do I apply that newly installed GCC version to be the default version that the terminal uses?

I am also aware that when you use homebrew to isntall gcc it names it gcc-49 so that there is no confusion between packages.

I have no idea how to replace the 4.2.1 version that comes with XCode with the 4.9 version I have installed.

Thanks

Edit: Switched to my mac to get the full return statement of gcc --version

Edit 2: My end game here is to be able to navigate to the directory and be able to type

make
sudo make install

to install the daemon that has been made. Right now that returns tons of errors with random packages and the Standard Library

解决方案

By default, homebrew places the executables (binaries) for the packages it installs into /usr/local/bin - which is a pretty sensible place for binaries installed by local users when you think about it - compared to /bin which houses standardisded binaries belonging to the core OS. So, your brew command should have installed gcc-4.9 into /usr/local/bin. The question is now how to use it... you have several options.

Option 1

If you just want to compile one or two things today and tomorrow, and then probably not use the compiler again, you may as well just invoke the gcc installed by homebrew with the full path like this:

/usr/local/bin/gcc-4.9 --version

Option 2

If you are going to be using gcc quite a lot, it gets a bit tiresome explicitly typing the full path every time, so you could put the following into your ~/.bash_profile

export PATH=/usr/local/bin:$PATH

and then start a new Terminal and it will know it needs to look in /usr/local/bin, so you will be able to get away with simply typing

gcc-4.9 --version

Option 3

If you just want to use gcc to invoke the compiler, without worrying about the actual version, you can do Option 2 above and additionally create a symbolic link like this

cd /usr/local/bin
ln -s  gcc-4.9  gcc

That will allow you to run the homebrew-installed gcc by simply typing gcc at the command line, like this

gcc --version

Note:

If you later want to install, say gcc-4.13 or somesuch, you would do your brew install as before, then change the symbolic link like this:

cd /usr/local/bin
rm gcc               # remove old link from gcc to gcc-4.9
ln -s gcc-4.13 gcc   # make new link from gcc to gcc-4.13

这篇关于OSX - 用通过Homebrew安装的4.9替换gcc 4.2.1版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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