升级到 El Capitan 后 gfortran 不工作

gfortran doesn't work after upgrading to El Capitan

我尝试升级到 El-Capitan 和 Xcode 7.0,但现在 gfortran 不起作用。每次我 运行 gfortran 时,我都会收到 google 搜索似乎无法解决的错误,所以我在询问堆栈溢出:

我正在尝试编译一个最小的示例程序:

program hello
print *, "Hello World"
end program hello

当我运行gfortran test.f

gfortran: warning: couldn’t understand kern.osversion ‘15.0.0
ld: library not found for -lgcc_s.10.4
collect2: error: ld returned 1 exit status

我不担心警告,但 ld 的错误才是真正困扰我的地方。 /usr/lib 文件夹中有 libgcc_s.10.4.tbd 但它似乎没有被 gfortran 使用。

谁能帮我解决这个问题,因为我想使用 gfortran 编译一些库?

更多信息:运行宁gfortran -v输出

gfortran: warning: couldn’t understand kern.osversion ‘15.0.0
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin12.2.0/4.8.0/lto-wrapper
Target: x86_64-apple-darwin12.2.0
Configured with: ../gcc-4.8-20120930/configure --enable languages=c++,fortran
Thread model: posix
gcc version 4.8.0 20120930 (experimental) (GCC)

您拥有的 gfortran 版本(安装在 /usr/local 中的 4.8 版本)不是苹果本应随 Xcode 一起分发的 GCC 版本(据我所知,他们从未使用过 GCC 版本在切换到没有 Fortran 前端的 llvm 之前是新的。在 el capitan 上随 Xcode 7 分发的 gcc 版本将自己标识为:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin15.0.0
Thread model: posix

您的版本来自其他地方并且太旧,无法识别 x86_64-apple-darwin15.0.0 目标。您需要更新该编译器才能正常工作 gfortran。 macports 和 homebrew 都可以在 OS X el capitan 上轻松安装 gcc/gfortran 的各种版本,我建议使用其中之一来安装 gcc。或者,您可以追踪之前用于安装 gcc 4.8 的任何内容,看看它们是否为 el capitan 提供更新。