无法在 MacOS Monterey 上编译 fortran:ld:YAML 文件中不支持的 tapi 文件类型“!tapi-tbd”

DdD*_*i20 7 gcc ld gfortran xcode-command-line-tools macos-monterey

每当我尝试编译 Fortran 代码时,都会遇到错误:

% gfortran Testing_Fortran.f90 -o Testing_Fortran

ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/lib/libSystem.tbd' for architecture x86_64 collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

通过互联网查看类似问题,我发现最常见的解决方案是降级 XCode 命令行工具,并重新安装 gcc,但这些都不起作用。

我尝试了 CLTools 14.1 和 13.4,并且通过自制程序安装 gcc。gfortran 版本是 12.2.0。我使用的是 MacOS Monterey 12.6。

有任何想法吗?提前致谢。

小智 10

我有类似的问题。我刚刚停用 Anaconda 并运行 fortran 代码。

conda deactivate
gfortran Testing_Fortran.f90 -o Testing_Fortranc
Run Code Online (Sandbox Code Playgroud)

您可以再次返回 Anaconda 环境,如下所示:

conda activate
Run Code Online (Sandbox Code Playgroud)


Set*_*son 7

您的系统链接器很可能ld不是最新的:无论是在此帮助单上还是与同事一起,问题都ld指向来自 Anaconda 的链接器。如果您的 $PATH 设置为 Anacondald比系统链接器具有更高的优先级,这将解释它:

$ which -a ld
/blah/anaconda3/bin/ld
/usr/bin/ld
Run Code Online (Sandbox Code Playgroud)

如果是这种情况,请重新排序您的 PATH,将 anaconda 的目录放在/usr/bin. 然后,which ld应该指向系统ld,然后就可以开始了。