【问题标题】:How to update g++ compiler on OSX如何在 OSX 上更新 g++ 编译器
【发布时间】:2018-11-03 05:04:47
【问题描述】:

我尝试使用this 教程下载最新版本的 g++,并将版本号从 4.7 更改为最新(相信是)8.1。但我收到以下错误

Error: No available formula with the name "gcc81"
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
git -C "$(brew --repo homebrew/core)" fetch --unshallow

Error: No previously deleted formula found.
==> Searching for similarly named formulae...
==> Searching local taps...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.

有人知道如何更新我的 g++ 版本吗?这是我尝试找出当前版本时得到的结果。

g++ --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

对不起,我是个菜鸟,我真的很想在这里学习。

【问题讨论】:

  • 我对自制软件了解不多,但您似乎没有安装任何 gcc。运行g++ 时得到的实际上是苹果安装的clang++ 编译器。苹果做的事情很奇怪,别名g++。所以你不需要像“安装”那样“升级”。无论如何,如果你尝试brew install gcc,没有版本会发生什么?
  • 我认为这些天你在 OSX 上尝试使用 gcc 可能会违背规律——Apple 正在努力让人们转向 clang。为什么需要它?
  • Homebrew gcc 8 由brew install gcc 安装。您可以brew search gcc 查找选项,brew info gcc 确定 gcc 包中提供的版本。为了防止 homebrew 安装的 gcc 与 mac 冲突,homebrew 在所有文件上都加上了-8 的后缀,所以gccgcc-8 调用,g++g++-8 调用。所以如果你使用makefile,你需要设置环境变量CC=gcc-8 CXX=g++-8,这些应该带入makefile,或者配置脚本。

标签: c++ macos g++


【解决方案1】:

我知道这篇文章有点老了,但我可以就如何实现这一点提出一些启示。

首先,要使用 Homebrew 安装 gcc/g++,您应该使用上面 cmets 中提到的以下命令:brew install gcc

完成此操作后,Homebrew 应将安装的二进制文件/符号链接放在正确的文件夹中。

为了在 mac 上正确设置 gcc/g++ 命令以使用您刚刚下载的版本,我这样做的方法是不更改符号链接 gcc/g++,而是为 gccg++ 在我的 shell 环境中。

alias gcc='gcc-10'
alias g++='g++-10'

gcc-10g++-10 是使用 Homebrew 下载的。执行此操作时,Homebrew 将 gcc-10g++-10 放在 /usr/local/bin (在路径上),它允许您为常规的 gcc/g++ 命令创建一个别名,这些命令指向由 Homebrew 安装的版本。

执行此操作后,运行命令 g++ --version 应该会为您提供以下信息:

g++-10 (Homebrew GCC 10.2.0) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

您可能需要重新启动终端或运行source ~/.bashrc,具体取决于您使用的外壳类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-04
    • 1970-01-01
    • 2017-08-19
    • 2013-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多