You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级至macOS SDK 15.2后Homebrew GCC编译报错:包含<stdio.h>时未知类型FILE

解决ARM macOS SDK 15.2下Homebrew GCC编译<stdio.h>报FILE类型未知问题

你遇到的是GCC固定头文件与macOS 15.2 SDK的兼容性冲突,以下是几个可行的解决方向:

  • 调整SDK版本
    编译时指定旧版本的macOS SDK(比如14.x系列,如果你还保留着)替换当前的15.2 SDK路径。修改编译命令中的-isysroot参数:

    -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.6.sdk
    

    若使用CMake,可在配置阶段指定:

    cmake -DCMAKE_OSX_SYSROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.6.sdk" ..
    
  • 绕开GCC的include-fixed目录
    GCC的include-fixed目录下的头文件和15.2 SDK不兼容,编译时禁用标准头文件自动包含,手动指定系统和GCC头文件路径:

    gcc-14 -nostdinc \
      -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include \
      -I/opt/homebrew/Cellar/gcc/14.2.0_1/lib/gcc/current/gcc/aarch64-apple-darwin23/14/include \
      [你的其他编译参数]
    

    对应CMake配置:

    if(APPLE AND CMAKE_C_COMPILER_ID STREQUAL "GNU")
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc")
        include_directories(SYSTEM /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include)
        include_directories(/opt/homebrew/Cellar/gcc/14.2.0_1/lib/gcc/current/gcc/aarch64-apple-darwin23/14/include)
    endif()
    
  • 切换旧版CommandLineTools
    如果你的机器上安装了旧版Xcode或CommandLineTools,切换过去可以使用兼容的SDK:

    sudo xcode-select -s /Applications/Xcode_15.0.app/Contents/Developer
    

这些方案都不需要切换到Clang,能保证Linux平台的可移植性。

内容的提问来源于stack exchange,提问作者Xmanoux

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 06:16:13