【问题标题】:Unable to compile C++ code after Xcode upgrade: <sys/cdefs.h> no such file or directoryXcode 升级后无法编译 C++ 代码:<sys/cdefs.h> no such file or directory
【发布时间】:2020-12-16 16:14:53
【问题描述】:

今天早上将 macOS BigSur 升级到 11.1 并将 Xcode 升级到 12.3 后,我的 MacPorts 2.6.4 发行版开始出现问题。我不能再用 GNU C++ v10.2.0_4 编译简单的 C++ 程序:

g++ -O3 -std=c++11 -c libvec.cpp
In file included from /opt/local/include/gcc10/c++/cmath:45,
             from libvec.cpp:1:
/opt/local/lib/gcc10/gcc/x86_64-apple-darwin20/10.2.0/include-fixed/math.h:45:10: fatal error: sys/cdefs.h: No such file or directory
45 | #include <sys/cdefs.h>
   |          ^~~~~~~~~~~~~
compilation terminated.

初步互联网搜索表明此问题可能是由于与 Xcode 命令行工具不一致造成的。请指导我如何调试和修复它?也许我需要在这样的升级后重新安装 MacPorts 发行版?谢谢!

【问题讨论】:

  • 查看 macports 邮件列表并询问 tgere

标签: terminal xcode macports


【解决方案1】:

这个问题确实是由 macOS 从 11.0 更新到 11.1 和 Xcode 从 12.2 更新到 12.3 引起的。 Apple 的新政策是在每次系统更新时增加 SDK 版本。由于此增量,与以前的 SDK 版本一起安装的 MacPorts GNU C++ 编译器现在失败。一个快速的解决方法是设置SDKROOT 环境变量以匹配新版本号:

export SDKROOT=`xcrun --show-sdk-path`

为方便起见,将此命令放入您的~/.profile 文件中。详细的问题解释和这个解决方案可以在 MacPorts 邮件列表的following thread 中找到。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-25
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    相关资源
    最近更新 更多