Fortran代码无法在Mac上使用gfortran进行编译 [英] Fortran codes won't compile on Mac with gfortran

查看:555
本文介绍了Fortran代码无法在Mac上使用gfortran进行编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近从Sun的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.
  • uninstall gfortran,
  • check that Xcode and its command line tools are up-to-date,
  • re-install 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命令行工具包括makegit以及编译器的命令行版本.您可以使用以下命令安装/更新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:

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

这是一个出色的实用程序,可检查您的自制软件配置是否正确.

which is a brilliant utility that checks your homebrew configuration is correct.

这篇关于Fortran代码无法在Mac上使用gfortran进行编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆