gfortran 12.2.0无法在带有MacOS Ventura 13.1-arm64的M1 Macbook Air上



gfortran无法在安装MacOS Ventura 13.1-arm64的M1 Macbook Air上运行

当我尝试编译任何程序时,例如

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

我得到以下错误信息:

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

似乎只有gfortran给出错误;我可以用gcc编译一个等价的C程序。

我尝试了一些事情:

  • 从Ventura 13.0更新到13.1,
  • 使用homebrew从安装的旧版本更新gcc
  • 使用https://github.com/fxcoudert/gfortran-for-macOS解除自制版本和安装gfortran的链接

但这些都没有任何影响。我已经安装了最新版本的Xcode,所以命令行工具是存在的。

关于我的设置的一些细节:

Xcode已安装,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

有人建议加入一个链接,但这又产生了另一个问题:

(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

因此,似乎存在链接问题和缺少对M1芯片的支持的问题。

对于如何解决这个问题有什么建议吗?

我开始怀疑我链接的SDK已经过时了。我搜索了"SDKs"在我的磁盘上找到了一个看起来更新的版本。所以我把链接改成了

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

现在gfortran似乎可以正常编译了。

最新更新