GFortran compiler error on Mac OS Big Sur

Solution 1:

@Jan12's answer didn't work for me.

Instead, brew uninstall gfortran followed by brew install gcc did it for me. I guess the gcc installation does a better job at setting the paths, but didn't bother checking in more detail.

Solution 2:

I have been able to fix the issue with the help of the following two posts:

  • https://developer.apple.com/forums/thread/666700
  • https://stackoverflow.com/questions/27314733/make-usr-local-lib-a-default-library-search-path-for-ld-on-mac-os-x

The problem is that after the update the System library is no longer in the search paths of the gcc. I solved this by adding it manually to the zprofile, so that anytime I run the Terminal, variable $LIBRARY_PATH is set.

To fix this issue

Edit file /private/etc/zprofile

Add this to the end of the file:

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

Restart Terminal