Skip to content

MacOS Compiler Environment

Marshall Ward edited this page Oct 15, 2022 · 14 revisions

Instructions for MacOS

This page includes specific instructions for compiling MOM6 on a MacOS system.

Many users have successfully built MOM6 on Macs, but many others have encountered challenges which were not always resolvable. Consider this page as a starting point, which will evolve over time to address these issues.

Dependencies

It is recommended that you first install the XCode development tools.

https://developer.apple.com/xcode/

You will need the following dependencies to compile the model:

  • Fortran compiler (GFortran, Intel Fortran)
  • netCDF, with Fortran bindings
  • MPI (OpenMPI, MPICH)

These can be installed with a package manager such as Homebrew or MacPorts. Another option is to use a Conda environment.

Instructions for Homebrew are shown below.

brew install make
brew install gfortran
brew install mpich
brew install netcdf
brew install netcdf-fortran

Many of the compilation instructions assume that an env file was created. These errors can be suppressed with an empty file.

echo > build/env

Note: make sure that brew is updated. In order to run brew update, you may first need to run the command git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow

Note 2: You may need to install Apple's command line developer tools by running xcode-select --install

Compilation

When building the Makefile with mkmf, you must select the appropriate MacOS template file. Three are currently included:

  • osx-gcc10.mk
  • macOS-gnu8-mpich3.mk
  • osx-gnu.mk

For the M1 chip with OS12.0.1, osx-gcc10.mk has been checked to work. Additional templates will be provided as we learn more about the needs of MacOS systems.

Troubleshooting

Differences across versions of MacOS can cause unexpected problems which are difficult to predict. For example, there may be incompatibilities between XCode tools and the GNU toolchain, such as installed by Homebrew.

As issues arise, they will be documented on this page.

An old Mac (2017)

During the build, I was getting stuff like: clang: error: invalid version number in ‘-mmacosx-version-min=11.0’ from MacOS version 11.7. The answer suggested by Dr Google worked:

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install