Compiling MOOG on OSX

Just a quick post for those who want to compile Chris Sneden‘s spectral line analysis package MOOG. Chris provides many helpful Makefiles with the code, including a few for Mac computers. The problem is it assumes we’re using the g77 FORTRAN compiler. Most new Macs will only deal with 64-bit binaries, so we have to use gfortran instead. Just changing the FC variable in the Makefile results in the dreated “symbol not found” errors:

[...] 
"_sm_ylabel_", referenced from:
 _binplot_ in Binplot.o
 _specplot_ in Specplot.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [MOOG] Error 1

The key problem here is that gfortran is looking for symbols like _sm_ylabel_ (one underscore before and one after the function name). But if you run nm on libplotsub.a; (the supermongo plotting library), you find:

$ nm /usr/local/lib/libplotsub.a | grep ylabel
0000000000000d10 T _sm_ylabel
 U _sm_ylabel
0000000000001560 T _sm_ylabel__
 U _sm_ylabel

So the solution is to get gfortran to add a second underscore when looking for external symbols from libraries. The needed switch is ‘-fsecond-underscore‘, which we can add to the FC variable in the Makefile:

FC = /usr/local/bin/gforgran -w -fsecond-underscore

Here is a complete recipe for compiling MOOG from scratch on a Mac (YMMV):

  1. If you haven’t already, download the gcc+gfortran binaries from the HPC for Mac site. Install these in your root folder.
    $ cd /; sudo tar -zxf ~/Downloads/gcc-{version}-bin.tar.gz
  2. Download the latest MOOG from Chris’ website. Extract to where you want MOOG to live.  For example:
    $ cd ~/bin
    $ mkdir MOOG
    $ tar -zxf ~/Downloads/MOOG{version}.tar.gz
  3. Download the latest supermongo (SM) and install according to its instructions. Make note of where the libraries are installed (usually /usr/local/lib)
  4. Edit Moog.f and update with settings for your local machine (see comments therein).
  5. Find the appropriate Makefile (Makefile.maclap or Makefile.macdesk) and make the change above to the FC variable.
  6. Update the SMLIB variable to point to the SM libraries.
  7. Chances are your local copy of SM doesn’t have Aquaterm support. If not, then comment out the AQLIB variable and remove the last part of the compile line in the Makefile: -L$(AQLIB) -laquaterm
  8. compile using your Makefile, for example:
    $ make -f Makefile.maclap
  9. Go fit some lines!
This entry was posted in Uncategorized. Bookmark the permalink.

Comments are closed.