macosarmgfortran

gfortran 12.2.0 not working on M1 Macbook Air with MacOS Ventura 13.1-arm64


gfortran does not work on my M1 Macbook Air with MacOS Ventura 13.1-arm64

When I try to compile any program, e.g.

program main
  print *, "Hello world."
end program main

I get the following error message:

(base) BL@MacBook-Air ~ % gfortran hello.f95 -o hello
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status

Only gfortran seems to give an error; I can compile an equivalent C program using gcc just fine.

I tried a few things:

But none of these made any difference. I have the latest version of Xcode installed, so the command line tools are present.

Some details about my setup now:

Xcode is installed, Version 14.2 (14C18)

(base) BL@MacBook-Air ~ % which gfortran
/usr/local/bin/gfortran
(base) BL@MacBook-Air ~ % which gcc
/usr/bin/gcc
(base) BL@MacBook-Air ~ % which ld
/usr/bin/ld

Somewhere somebody suggested including a link, but that gave another problem:

(base) BL@MacBook-Air ~ % gfortran hello.f95 -o hello -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd, missing required architecture arm64 in file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd

So there seems to be both a linking problem and a problem with missing support for the M1 chip.

Any suggestions on how to solve this?


Solution

  • I started to suspect that the SDK which I linked to was outdated. I searched for "SDKs" on my disk and found a version which looked newer. So I changed the link to this:

    -L/System/Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib

    Now gfortran seems to compile as expected.