OSX - 用通过 Homebrew 安装的 4.9 替换 gcc 版本 4.2.1

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

问题描述

这已经困扰我一段时间了.我正在尝试编译一个巨大的 C++ 文件(我知道它可以正常工作,因为它在我的 Arch Linux 计算机上运行良好).当我在我的 mac 上检查我的 GCC 版本时,它返回以下内容

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

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

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

brew install gcc49

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

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

我也知道,当您使用自制软件来安装 gcc 时,它会将其命名为 gcc-49,这样包之间就不会混淆.

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.

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

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

谢谢

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

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

推荐答案

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

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.

选项 1

如果你今天和明天只想编译一两件事,然后可能不会再使用编译器,你不妨调用homebrewgcc> 完整路径如下:

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

选项 2

如果您打算大量使用 gcc,每次都明确输入完整路径会有点烦人,因此您可以将以下内容放入您的 ~/.bash_profile

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

然后启动一个新终端,它会知道它需要查看/usr/local/bin,因此您只需输入

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

选项 3

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

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

这将允许您通过在命令行输入 gcc 来运行 homebrew 安装的 gcc,就像这样

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

gcc --version

注意:

如果你以后想安装,比如 gcc-4.13 或类似的,你可以像以前一样执行 brew install,然后像这样更改符号链接:

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


请注意,如果您实际使用的是 C++ 而不是 C,则需要针对 g++ 修改上述内容以代替 gcc.


Note that if you are actually using C++ rather than C, you will need to adapt the above for g++ in place of gcc.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Returning a pointer of a local variable C++(返回局部变量 C++ 的指针)
Inline function linkage(内联函数联动)
Which is more efficient: Return a value vs. Pass by reference?(哪个更有效:返回值与通过引用传递?)
Why is std::function not equality comparable?(为什么 std::function 不具有可比性?)
C++ overload resolution(C++ 重载解析)
When to Overload the Comma Operator?(什么时候重载逗号运算符?)