Skip to content

MacOS Compiler Environment

Mitch Bushuk edited this page Oct 12, 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.

Instructions for Homebrew are shown below.

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

Compilation

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

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

For the M1 chip with OS12.0.1, the following changes were reuqired to the osx-gnu.mk makefile:

git diff diff --git a/templates/osx-gnu.mk b/templates/osx-gnu.mk index 6be1067..42e448b 100644 --- a/templates/osx-gnu.mk +++ b/templates/osx-gnu.mk @@ -81,6 +81,7 @@ MAKEFLAGS += --jobs=$(shell sysctl -n hw.ncpu)

Required Preprocessor Macros:

CPPDEFS += -Duse_netCDF +CPPDEFS += -DHAVE_GETTID

Additional Preprocessor Macros needed due to Autotools and CMake

@@ -96,7 +97,7 @@ endif FPPFLAGS += $(shell nf-config --fflags)

Base set of Fortran compiler flags

-FFLAGS := -fcray-pointer -fdefault-double-8 -fdefault-real-8 -Waliasing -ffree-line-length-none -fno-range-check +FFLAGS := -fcray-pointer -fdefault-double-8 -fdefault-real-8 -Waliasing -ffree-line-length-none -fno-range-check -fallow-invalid-boz -fallow-argument-mismatch

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