問題
在用brew安裝GCC時, 報了如下錯誤.
➜ ~ brew install gcc
==> Installing dependencies for gcc: isl, mpfr and libmpc
==> Installing gcc dependency: isl
==> Downloading https://homebrew.bintray.com/bottles/isl-0.20.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring isl-0.20.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/isl/0.20: 71 files, 3.9MB
==> Installing gcc dependency: mpfr
==> Downloading https://homebrew.bintray.com/bottles/mpfr-4.0.1.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mpfr-4.0.1.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/mpfr/4.0.1: 28 files, 4.6MB
==> Installing gcc dependency: libmpc
==> Downloading https://homebrew.bintray.com/bottles/libmpc-1.1.0.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libmpc-1.1.0.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/libmpc/1.1.0: 12 files, 354KB
==> Installing gcc
Warning: Building gcc from source:
The bottle needs the Xcode CLT to be installed.
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
Error: An exception occurred within a child process:
CompilerSelectionError: gcc cannot be built with any available compilers.
Install GNU's GCC
brew install gcc
原因是 在從App Store上下載Xcode后,默認是不會安裝Command Line Tools的.
解決方法
這時需要先更新一下xcode
xcode-select --install