【发布时间】:2019-10-03 00:31:00
【问题描述】:
我在尝试使用 gfortran 编译一个简单的 fortran-90 文件时遇到一个奇怪的错误。我正在开发 macOS mojave 系统。我已经安装了 gfortran 8.2.0,并通过执行以下操作来确保这一点:
Input: gfortran --version
Output: GNU Fortran (GCC) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
这表明 gfortran 安装正确,我还通过在终端中简单地输入:gfortran,然后返回:
gfortran: fatal error: no input files
compilation terminated.
但是,当我尝试像这样编译我的文件时:
gfortran hello.f90 -o hello.x
我收到一条错误消息:
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status
我尝试过以不同的方式进行编译,还尝试按照https://gcc.gnu.org/wiki/GFortranBinaries32Linux 的描述在 .bash_profile 中设置 LD_LIBRARY_PATH,但我仍然遇到同样的错误。 gfortran 目录的路径名是:/usr/local/gfortran,但是在 /usr/local/bin 中可以找到另一个不是目录的 gfortran
打字:
which gfortran
输出:
/usr/local/bin/gfortran
并对该目录进行长列表搜索:
Input: ls -l /usr/local/bin/gfortran
Output: lrwxr-xr-x 1 root wheel 32 15 May 14:07
/usr/local/bin/gfortran -> /usr/local/gfortran/bin/gfortran
如果一切似乎都已正确安装,我该如何解决这个问题?
任何帮助将不胜感激!
【问题讨论】:
-
你安装了xcode命令行工具吗?根据 gfortran 二进制文件,可能需要这些文件才能正常工作。您可能还想使用例如自制程序构建,这些都是最新的。
-
@janneb 我确实为 xcode 安装了命令行工具,我在另一个苹果设置上尝试了自制程序构建,但出现了同样的问题,但我可以在这台计算机上尝试
-
命令行工具已过时。解决方案:
sudo rm -rf /Library/Developer/CommandLineTools,然后是xcode-select --install,sudo xcode-select --switch /Library/Developer/CommandLineTools,如果 Xcode 太过时,更新 Xcode。毕竟,如果你安装了 Xcode,你可能想sudo xcode-select -s /Applications/Xcode.app。
标签: xcode macos gcc fortran gfortran