使用 gfortran 无法在 Mac 上编译 Fortran 代码 [英] Fortran codes won't compile on Mac with gfortran
问题描述
我最近从 SGI、Sun 工作站环境转移到了 Mac.SGI 和 Sun 带有 Fortran 编译器,所以我可能有 100 个小 f77 代码,这些代码是我多年来编写的,用于对模拟数据进行后处理和分析.我希望使用 gfortran 在我的 iMac 上运行这些代码.其中大部分都是非常简单的代码,但我无法编译和执行它们.我尝试从基础开始,并从 gfortran 帮助页面编写 Hello World 代码.我的代码 fortran.f 是:
I recently moved from the SGI, Sun workstation environment to a Mac. SGI and Sun came with Fortran compilers so I have maybe 100 small f77 codes I wrote over the years for post-processing and analysis of simulated data. I was hoping to get these codes running on my iMac with gfortran. Most of these are very simple codes but I can't get them to compile and execute. I tried starting with the basics and wrote the Hello World code from a gfortran help page. My code, fortran.f is:
program helloworld
print *, "hello world"
end program helloworld
当我尝试根据我输入的示例编译它时:
When I tried compiling this according to the example I typed:
gfortran fortran.f
但我不断收到错误消息:
But I keep getting the error message:
FATAL:/opt/local/bin/../libexec/as/x86_64/as: I don't understand 'm' flag!
这与我在其他代码中收到的错误消息相同.有人可以告诉我我做错了什么吗?我想不出一个更简单的例子,但我似乎无法让它发挥作用.
This is the same error message I get on my other codes. Can someone tell me what I'm doing wrong? I can't think of a simpler example but I can't seem to get it to work.
推荐答案
如果您的 gfortran
是很久以前安装的,并且您在安装后更新了 macOS,它可能需要重新安装才能正确对齐并与最新的 macOS 工具和库链接.
If your gfortran
was installed a long time ago and you have updated macOS since installing, it may need re-installing to get correctly aligned and linked with the latest macOS tools and libraries.
我的建议是:
- 卸载
gfortran
, - 检查 Xcode 及其命令行工具是否是最新的,
- 重新安装
gfortran
.
每个步骤的提示如下:
请注意,gfortran
是 GCC 的一部分 - GNU 编译器集合".
Note that gfortran
is a part of GCC - the "GNU Compiler Collection".
如果您通过 homebrew 安装了 gfortran
,则可以使用以下命令将其删除:
If you installed gfortran
via homebrew, you can remove it with:
brew rm gcc
您可以通过转到 AppStore 并单击右上角的 Updates
来更新 Xcode.
You can update Xcode by by going to AppStore and clicking Updates
at top-right.
Xcode 命令行工具包括 make
和 git
以及编译器的命令行版本.您可以安装/更新 Xcode 命令行工具:
The Xcode Command Line tools include make
and git
and command-line versions of the compilers. You can install/update the Xcode command line tools with:
xcode-select --install
您可以使用 homebrew 安装 gfortran
:
You can install gfortran
with homebrew using:
brew install gcc
当你完成后,你应该确保你的 PATH
在开始附近包含 /usr/local/bin
并且运行时没有错误:
When you are finished, you should make sure that your PATH
includes /usr/local/bin
near the start and that there are no errors when you run:
brew doctor
这是一个出色的实用程序,可以检查您的 homebrew 配置是否正确.
which is a brilliant utility that checks your homebrew configuration is correct.
这篇关于使用 gfortran 无法在 Mac 上编译 Fortran 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!