F951: Fatal Error - I need help to compile my first code (macOS 12.4)

Hi All,

I am totally new to this coding stuff, after taking a break of almost 25 years from FORTRAN, decided to come back to it for fun purposes. I saw the Fortran lang on youtube and then subsequently looked at the website for info and a tutorial.

After figuring out what i needed to download and install on my iMac, OS Monterey 12.4 with intel chips from your website i am now in a position to run my first code Hello World from your website. But then in the terminal window i get this:

f951: Fatal Error: Cannot open file ā€˜hello.f90ā€™
compilation terminated.

As per your website instructions iā€™ve installed the following:

Home Brew as per their instruction on their website
(i figured this was the Fortran compiler)

Atom, the relevant libraries, [IDE-FORTRAN by hansec], [atom-ide ui by facebook-atom], [language-fortran by dparkins], Python and FORTRAN LANGUAGE SERVER.
(to be used as the text editor)

I used Home brew to install the FORTRAN LANGUAGE SERVER as well. info on how to do that from their website

So i opened up a new Atom editor window, typed in Manually the code from your tutorial website, saved as hello.f90 file, to the following location:

macdisk/home/documents/coding

went to the terminal and on the command line typed gfortran hello.f90 -o hello

Then i get aforementioned error. To be clear my command prompt was computername:~ home$

Any ideas to help me outā€¦?

The last time i used FORTRAN was on a windows machine, it was FORTRAN 77 and i used a 3.5 inch disk in order to install it on the windows, via DOS! :wink:

Also let me be absolutely clear, i need absolute baby steps, i am not a programmer, or a coder, or a software guy, i have no clue about Terminal, unix, Mac OS at command line level and really donā€™t know what i am doing. Itā€™s a learning curve.

many thanks in advance for any tit bits or advice to get me up and running.

1 Like

The directory where you saved your source file (using the Atom editor) is probably not the directory that you find yourself in when you open the terminal window.

Try this - open the source file in the editor again, make some trivial modification, and save the file, but make a note of the directory where the file is saved. Then, when you open the terminal window, change to the directory that you made a note of in the preceding step.

Hi Mecej4,

thanks for quick answerā€¦i figured that might be the case, and perhaps also beyond the scope of this forum, but i have no clue how to do that in Terminal. change a directory or move or anything like,

I know where it is saved, /coding folder, the terminal command line is my home folder$

Itā€™s definitely not the same folder, directory or pathā€¦or whatever itā€™s called.

OK, i managed somehow to change the directory to where my saved code is from the Atom text editor. More luck than judgment i think.

Now i have a new problem.

After running gfortran hello.f90 -o hello another error has popped up

clang: error: invalid version number in 'macosx-version-min=12.0

well if understand that correctly itā€™s saying that my Mac OSX isnā€™t high enough for this to run, however, i am definitely running Mac OSX 12.4

How can i resolve this now?

If you are looking for some reading material, you might check out https://qc2-teaching.readthedocs.io/en/latest/install.html#macos and https://qc2-teaching.readthedocs.io/en/latest/intro.html, which we are using for teaching chemistry students with no prior programming experience. I started programming from this resources not too long ago (5 years now).

Any questions around this topic are very well on scope for this forum, we all were all beginners at some point and are more than happy to help you get started.

My wild guess (backed by a random search result: How to update Xcode from command line - Stack Overflow) would be that XCode command line tools are not properly setup. I presume you have installed them using xcode-select already:

xcode-select --install

The recommended steps there seem to be switching with

sudo xcode-select --switch /Library/Developer/CommandLineTools/

Or resetting

sudo xcode-select -r

the command line tools. The suggestions involving rm -rf /Library/Developer/CommandLineTools/ seem like a too drastic step here.

Maybe the MacOS using developers here can give a more qualified assessment.

I think the Homebrew install on MacOS also does the Xcode command line tool install, so unless something odd is happening with the install, it should all be consistent afterwards.

I think at this point @servant needs to read a little about how to use unix, how shells work, how directories work and so on. The book I learned this from back in the 1980s is

The programming examples are in C, but fortran will work pretty much the same way. It probably isnā€™t a bad idea to learn a little C anyway, even if your focus is fortran. There are probably some online sources for this kind of information now, and to be upfront, most things in that book have been updated since then (shells, make, vi, ar, the C language, etc.). The good thing about this is that once you learn it, you can use that knowledge for decades. It is the foundation for essentially all the programming advances that have occurred in the last 40 years, and will continue to be so for the foreseeable future.

@awvwgk

Thanks for tips, iā€™ll have to review those at some point, not as though Chemistry was ever my strong point, i got kicked out of class for being too crappy. But still, iā€™m sure itā€™s not the chemistry thatā€™s important in this case, rather the coding experience and knowledge

As for Xcode, well i did a check and it seems i have xcode installed, some how, after doing Xcode-select -p i got back /library/developer/commandlinetools, which doing some research from stack overflow tells me that itā€™s installed. And as @RonShepard pointed out itā€™s part of Homebrew (i seem to recall before installing that this Xcode was included in Homebrew)

I also tried installing xcode from the App Store, for it to only tell me that i donā€™t have enough space to perform the install, i have over 37GB available on the OS drive (iā€™m assuming this is called root drive), which should be sufficient as the download is only 12GB. However on further reading, iā€™m being told that it needs a scratch space or something or other for the download, install etc.

So then i started looking into 2 things 1. moving some applications out of the OS folder to somewhere else, or, 2, downloading Xcode via the command line, as a compressed version but then as @RonShepard has said, that HomeBrew already has Xcode in itā€¦

This is all too confusing for me to doā€¦all i wanted to do was download FORTRAN, maybe an editor, and play around with itā€¦now it looks like i need to learn unix, shells, how directories work, i appreciate the input @RonShepard but thatā€™s a little overwhelming for me at this stage, i was just starting to get my head around coding and using the editor. However i will take it on board and itā€™s now in my amazon wish list.

Has any one got a fix so that i can just get the compiler to run, so i can just get started, and then, i can start to learn the other stuff as and when needed. It was just only for a bit of fun and quite rightly perhaps learn C, or Python (i had to install that as well along the way) as i progress.

Much appreciated for any input againā€¦and apologies to all if this seems trivial to most of youā€¦

You could have a look into Visual Studio Code and the Modern Fortran Extension (Modern Fortran - Visual Studio Marketplace), this should serve most of your needs to get started with Fortran programming without having to worry too much about Unix, Shells and co.

You could use an online compiler like https://godbolt.org/
Nothing to install on your macOS. You can start immediately in your browser. Itā€™s sufficient to relearn Fortran basics.

Yes, it is a lot, but I predict that you will enjoy the process. That book is well written and is a pleasure to read.

As for your gfortran problem, what happens when you type the following into a terminal window?

which gfortran
gfortran --version

@RonShepard

In response to which gfortran, i get /usr/local/bin/gfortran

In response to gfortran --version, i get
GNU Fortran (Homebrew GCC 12.1.0) 12.1.0
Copyright blah blahā€¦

I take your point about the book, and you are more than right, iā€™d probably enjoy it once i got into itā€¦having seen a few pages alreadyā€¦but itā€™s not my main purpose right nowā€¦perhaps in the future i will regret not doing it this way, but this is just for a fun project of coding and learning to code. Just because i canā€™t do it.

Hi @vmagnin

if only i had known about this earlier, perhaps this would have been the better solution, but i just followed the steps of fortran-lang tutorial etc and how to get startedā€¦i wasnā€™t aware of these other options, and honestly i thought it would be an easy install (itā€™s a mac after all), now iā€™m beginning to re-evaluate that remark of it being a mac.

1 Like

Start having fun with Fortran in Godbolt. It may then give you the motivation to fight with the installation on your mac in order to go further with the language! (mac people here will help you) But fun first!

again i installed the VS Code and the extension to get the FORTRAN code in and checked for bugs, however, again i have the same issue when trying to compile that code in FORTAN in the terminal,

clang: error: invalid version number in ā€˜-macosx-version-min=12.0ā€™

so although the user interface of the Modern fortran is nice and quick in the VS Code interface, the compiler on my mac still doesnā€™t want to playā€¦

any suggestions anyone?

getting frustrating now :angry: ā€¦i make take up @vmagnin on their idea of running it on a browser for nowā€¦

On the surface, it looks like the gfortran compiler was installed correctly. My Mac is an arm64 machine, and Homebrew works a little differently here than on an intel machine. On my laptop, I must execute the command

test -r /opt/homebrew/bin/brew && eval ā€œ$(/opt/homebrew/bin/brew shellenv)ā€

On my machine, this resets PATH and MANPATH and it defines a few environment variables. Is there anything similar that the intel Homebrew users are supposed to do?

Regarding the comment about the Mac being easy to use, when it comes to programming, it looks like a unix/posix machine. Maybe a few things are easier than on a typical linux box, but mostly it looks the same. I donā€™t use the Xcode development environment (which as you noted is about 30 GB of disk space), I just use the command line tools.

Hi, I may be late to the party, but all you have to do is go to the terminal you got the error from in the original post and do the:

cd ~/documents/coding

Then, you do the command

gfortran hello.f90 -o hello

gfortran expects that your hello.f90 file is in the same folder as your code and by default is not (you can check that with the command pwd in the terminal).

That should do it.

Hi @14ngp

thanks for your reply, however, if you look above iā€™ve already done that, and then got the clang: error: invalid version number in ā€˜-macosx-version-min=12.0ā€™, `and now this is the issue iā€™m having, but yet iā€™m running 12.4 Monterey.

Hi @RonShepard

Ooo looks very technical for meā€¦but to make sure, that i understand correctly, that youā€™re using Homebrew too, but itā€™s on your Apple Silicon, rather than the Intel macs? Hence why this command line works on your Apple Silicon and not the Intel?

So therefore i shouldnā€™t use this line youā€™ve got posted on my Intel Mac. Not sure where to go and get support from Home brew to find the equivalent for Intel Macs. Iā€™ll try and do some research though as well.

Oh I thought you had tried switch compilers or something I didnā€™t noticed that was a gfortran output. I didnā€™t know clang was involved with GCC in macOS, that looks suspicious. Try using a locate command:

locate gfortran

Maybe your real binary is hiding somewhere else, like in /usr/bin/gfortran

In which case, instead of calling it by just ā€œgfortranā€ you would need to:

/usr/bin/gfortran hello.f90 -o hello

@14ngp

oh well nowā€¦that has stirred up some more stuffā€¦the locate gfortran command created another message on my iMac namely:
WARNING The locate database (var/db/locate.database) does not exist. To create the database, run the following command:
sudo launchct1 load -w /system/library/launchdaemons/com.apple.locate.plist

Please be aware the the database can take some time to generate; once the database has been created, this message will no longer appear.

So as itā€™s a sudo command, iā€™m not doing that until i know what it will do/is dangerous.

I think now itā€™s less of a gfortran/homebrew issue, itā€™s more of a whatā€™s my mac doing and why is it saying thereā€™s min mac osx version of 12.0 when i know for sure i have 12.4 - thatā€™s what i need help with right now.