Mac mini OS再インストール >>>「gccがコンパイルできない」を解決

Mac miniのOSの再インストールをした。
すると、cがコンパイルできない。

そこで、自分の過去の記事
http://would-be-astronomer.hatenablog.com/entry/2014/12/24/022813
を元に、環境の復元を行った。(大したことはなかった)

(症状1)
$ gcc -o test test.c -lgsl -lgslcblas -lm
fatal error: stdio.h: No such file or directory

そこで、gcc とかの設定が失われているのではと思い、調べて見る。

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin14/4.7.4/lto-wrapper
Target: x86_64-apple-darwin14
Configured with: /opt/local/var/macports/build/_opt_mports_dports_lang_gcc47/gcc47/work/gcc-4.7.4/configure --prefix=/opt/local --build=x86_64-apple-darwin14 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc47 --includedir=/opt/local/include/gcc47 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.7 --with-libiconv-prefix=/opt/local --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.7 --with-gxx-include-dir=/opt/local/include/gcc47/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --disable-cloog-version-check --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --disable-ppl-version-check --with-pkgversion='MacPorts gcc47 4.7.4_3'
Thread model: posix
gcc version 4.7.4 (MacPorts gcc47 4.7.4_3)

という結果を得て、どうもgccには問題ない模様。

つぎに、
$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
この結果は自分の過去の記事と同じ。

$ xcode-select --install
xcode-select: note: install requested for command line developer tools
この結果は、「command line developer tools」がインストールされていないことを示唆。
そのまま待つと、インストールしますか?的に聞かれるのでYesとする。
2 minほどでインストール完了。

その後、試しに以下のように打つ。
$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
インストールができていることがわかる。

念のため、新しいterminalを立ち上げて、home directoryで
$ source .bash_profile
を行う。

すると、今度はコンパイルができた。

$ gcc -o bessel_example_1_val_and_err bessel_example_1_val_and_err.c -lgsl -lgslcblas -lm
$ ./bessel_example_1_val_and_err
status = success
J0(5.0) = -0.177596771314338264
+/- 0.000000000000000193
exact = -0.177596771314338292