Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

macos - Fortran codes won't compile on Mac with gfortran

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When it comes to macOS, I think that building form sources is the best approach you can have. You can achieve that quite easily by downloading and compiling GFortran as part of GCC directly from: https://gcc.gnu.org/wiki/GFortran

However, there are few things you have to take care of:

  • make sure you have XCode installed, you can get it here

    XCode

    XCode is free of charge

  • Make sure you have command line tools

    You can get them either from developer.apple.com

    Command Line Tools

    or directly from XCode. It might be that XCode will tell you to install Command Line Tools upon first execution

    enter image description here

    In the past, running command like "svn", when Command Line Tools were not installed, also triggered the installation.

  • Compile GCC

    > ./configure --prefix=$HOME/opt/usr/local
    > make all
    > make install
    
  • Alternatively, you can install using macOS package from GFortran

    gfortran-6.3-Sierra.dmg

Fully working sample with Fortran based MPI code:

http://www.owsiak.org/running-open-mpi-on-macos/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...