LoginSignup
8
6

More than 3 years have passed since last update.

macOSでgccが入らない

Last updated at Posted at 2019-12-20

環境

  • MacBook Pro (13-inch, 2017)
  • macOS Catalina(10.15.2)

エラーが出る

$ brew install gcc
()
make[3]: /private/tmp/gcc-20191220-61140-9wayo/gcc-9.2.0/build/./gcc/xgcc: Permission denied
/bin/sh ../../../libgcc/../move-if-change tmp-libgcc_tm.h libgcc_tm.h
make[3]: *** [avx_resms64fx_s.o] Error 1
make[3]: *** Waiting for unfinished jobs....
echo timestamp > libgcc_tm.stamp
make[2]: *** [all-stage1-target-libgcc] Error 2
make[1]: *** [stage1-bubble] Error 2
make: *** [all] Error 2

READ THIS: https://docs.brew.sh/Troubleshooting

image.png
リンク先を見ると「複数のターミナルを起動してるとエラーになるよ」(意訳)というのを見つけてコレだ!と思うものの、単一のウィンドウでやっても結果変わらず。

何度かやってダメだなー、俺、ダメだなーってなってた訳ですが。

$ brew install gcc
Updating Homebrew...
Warning: Building gcc from source:
  The bottle needs the Xcode CLT to be installed.

brew install gcc したときに出る The bottle needs the Xcode CLT to be installed. が気になりまして。💡

参考:Mac Homebrewでgccのインストールに時間がかかる場合はXcode Command Line Tool (CLT)をインストールしておけば良い

を参考にしてインストール。「インストールに失敗しました」……でも。

$ xcode-select --install
xcode-select: note: install requested for command line developer tools
$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

エラーを見ると、「コマンドラインツールはもうインストールされている」と出ているではないですか。もう一度インストールにチャレンジ。

$ brew install gcc
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/gcc-9.2.0_2.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/15/1564397f461f629f3811f1ececc7f2bb614f7520242743fc41348d190d8b6aa9?__gda__=exp=1576817568~hmac=a4098a424af8b81a10c47
######################################################################## 100.0%
==> Pouring gcc-9.2.0_2.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/gcc/9.2.0_2: 1,462 files, 287.9MB
$ 

入りました 🎉

なんで必要になったのか

$ g++ program.cpp
program.cpp:1:10: fatal error: 'bits/stdc++.h' file not found
#include <bits/stdc++.h>
         ^~~~~~~~~~~~~~~
1 error generated.

bits/stdc++.hがない、と言われてしまったため。

解決方法

$ cd /usr/local/include/
$ ln -s /usr/local/Cellar/gcc/9.2.0_2/include/c++/9.2.0/x86_64-apple-darwin19/bits

無事にg++でコンパイルできるようになりました。 🎉

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6