4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MacのC++コンパイラをHomebrewで最新版にする

Last updated at Posted at 2019-06-13

はじめに

はじめまして。うまあんです。

今回はC/C++コンパイラを最新のものにします。

インストール

Homebrewでインストールします。

$ brew install gcc

これでインストールが終わりました。
Homebrew経由入れたパッケージは/usr/local/Celler/にインストールされ、usr/local/bin/にリンクされます。

エイリアスを探す

/usr/local/bin/からエイリアスを探し当てます。

$ ls /usr/local/bin | grep gcc
$ ls /usr/local/bin | grep g++

gcc-9とg++-9が目当てのエイリアスです。

シンボリックリンクの作成

シンボリックリンクはOSのファイルシステムの機能の一つで、簡単に言うと特定ファイルやディレクトリを参照する別のファイルのことです。

シンボリックリンクは以下のコマンドで作成できます。

ln -s [シンボリックリンクを作成したいファイルのパス] [シンボリックリンクを置くフォルダのパス]

実際にシンボリックリンクを作成します。ついでにgccも更新しておきましょう。

$ ln -s /usr/local/bin/gcc-8 /usr/local/bin/gcc
$ ln -s /usr/local/bin/g++-8 /usr/local/bin/g++PATHを通す

PATHを通す

~/.bash_profileに以下の記述をして、パスを通します。

export PATH=$PATH:/usr/local/bin

コンパイラのインストールで起こる問題

Xcode CLTがインストールされていないと時間がかかるようです。

Xcode CLTを以下のコマンドでインストールします。

xcode-select --install

結果

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/9.1.0/libexec/gcc/x86_64-apple-darwin18/9.1.0/lto-wrapper
Target: x86_64-apple-darwin18
Configured with: ../configure --build=x86_64-apple-darwin18 --prefix=/usr/local/Cellar/gcc/9.1.0 --libdir=/usr/local/Cellar/gcc/9.1.0/lib/gcc/9 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 9.1.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
Thread model: posix
gcc version 9.1.0 (Homebrew GCC 9.1.0)

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/9.1.0/libexec/gcc/x86_64-apple-darwin18/9.1.0/lto-wrapper
Target: x86_64-apple-darwin18
Configured with: ../configure --build=x86_64-apple-darwin18 --prefix=/usr/local/Cellar/gcc/9.1.0 --libdir=/usr/local/Cellar/gcc/9.1.0/lib/gcc/9 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 9.1.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
Thread model: posix
gcc version 9.1.0 (Homebrew GCC 9.1.0) 

4
3
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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?