Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何更新g++;OSX上的编译器_C++_Macos_G++ - Fatal编程技术网

C++ 如何更新g++;OSX上的编译器

C++ 如何更新g++;OSX上的编译器,c++,macos,g++,C++,Macos,G++,我尝试使用教程下载最新版本的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

我尝试使用教程下载最新版本的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++
,您应该使用上面评论中提到的以下命令:
brew install gcc

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

要在mac上正确设置
gcc
/
g++
命令以使用您刚刚下载的版本,我不更改符号链接
gcc
/
g++
,而是在shell环境中为
gcc
g++
创建别名

alias gcc='gcc-10'
alias g++='g++-10'
gcc-10
g++-10
使用自制软件下载。进行此操作时,Homebrew将
gcc-10
g++-10
放在/usr/local/bin(路径上),并允许您为指向Homebrew安装的版本的常规
gcc
/
g++
命令创建别名

执行此操作后,运行命令
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
,具体取决于您使用的shell类型。

我对自制软件不太了解,但您似乎没有安装任何gcc。运行
g++
时得到的实际上是苹果安装的
clang++
编译器。这是苹果公司做的一件奇怪的事情,别名为
g++
。所以你不需要“升级”而需要“安装”。不管怎么说,如果您尝试
brew安装gcc
,但没有版本,会发生什么?我认为您最近在OSX上尝试使用gcc可能是违反规则的-苹果正在努力让人们转向clang。为什么需要它?自制gcc 8由
brew安装gcc
安装。您可以
brew search gcc
查找选项,也可以
brew info gcc
确定gcc软件包中提供的版本。为了防止自制安装的gcc与mac版本发生冲突,自制在所有文件上都添加了后缀
-8
,因此
gcc
gcc-8
调用,
g++
g++-8
调用。因此,如果您使用的是makefiles,您应该设置环境变量
CC=gcc-8 CXX=g++-8
,这些变量应该包含在makefile中,或者配置脚本。