Friday, June 18, 2021

Getting gfortran to Work on a Mac

 Everything was good with my grotty old copy of gfortran -- great even -- until Apple changed the default shell from bash to zshell sometime last winter in the OS 11.4 Big Sur upgrade.  It took a while to get things going again recently.  What follows are both notes to self, and perhaps a rescue line to the truly perplexed.  Here we go.

  1. Just get the new compiler.  GitHub is a dandy place but there are others.  It comes in the usual dmg format, so it unpacks and installs and all that automagically.
  2. Likewise, get the latest Xcode developer kit from Apple.  It's free, but it's also > 10 GB so it might take a while to download.
  3. Here's the fun part, getting the linker to work.  There's a little scrap of code to paste at the bottom of /private/etc/zprofile at this link.  (also, pasted in at the bottom of this post) You're going to have to reset the protections on that file before you can edit it though, via the incantation: sudo chmod 664   You will be asked for the system password.  Be sure to change it back via sudo chmod 444 when done, or some bad magic might leak in.
  4. One more step (also found at the above link), type xcode-select --install into the command line window.  Then go fishing, while a couple more GB of stuff gets downloaded from from the Apple servers.  (Only caught hardheads, bleh.  Still it was better than sitting around worrying about the slow download rate.)
  5. Re-start the terminal program before you can expect anything to work.
  6. Test it with a "hello world" sort of program.  When it's all working, drink a lot of rye whisky and read something fun like Andy Weir's latest.
OK, that was a mean day's work.  Here's that little scrap of path setup code, in case the above link ever goes away.  OK, I'm done, time to get back to work with a functioning compiler.  Yes, it's 8:30 on a Friday night.
if [ -z "${LIBRARY_PATH}" ]; then
    export LIBRARY_PATH="/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
else
    export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
fi

No comments:

Post a Comment