LoginSignup
1
0

More than 1 year has passed since last update.

MacでFortranとC++コードをコンパイルできない問題

Last updated at Posted at 2021-05-07

私のMacBook Pro(MacOS Big Sur, ver11.3)で1年以上ぶりにfortranのコードをgfortranでコンパイルしようとしたところ、以下のようなエラーが発生。

$ gfortran ex_sum.f90 
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status

よくわからんが、ライブラリが見つからんとのこと。
いろいろ調べた結果、gccのバージョンが古い(ver. 7だった)ことに気づき、とりあえずアップデートしたら解決しました、という話です。
gccをアップデートしたらgfortranもアップデートされました。

下のコマンド

$ brew upgrade gcc

でHomebrewを使ってgccをアップデートしようとしたらいくつかエラーが出てきました。
その中に

Error: gcc: the bottle needs the Xcode CLT to be installed.

があったので、これを調べたら

$ xcode-select --install

で解決するという記事を見つけました[1,2]。
途中、command line developer toolsをインストールしろと言われたので指示通りインストールしました。次に

$ brew upgrade gcc

で無事gcc(gfortran含む)のバージョンをアップデートできました。
最後にgfortranでコンパイルしてみました。

$ gfortran hello.f90 
$ ./a.out 
 HELLO WORLD

参考:
[1] https://qiita.com/takepan/items/2ceeab4690e726a08c57
[2] https://rcmdnk.com/blog/2019/02/26/computer-mac-homebrew/

1
0
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
1
0