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

Apple Silicon链接时出现ld: library not found for -lSystem错误求助

Apple Silicon汇编程序链接libSystem失败的解决办法

你的链接命令存在两个关键问题,导致找不到libSystem库:

  1. -syslibroot参数的命令执行语法错误
    你用了单引号'包裹xcrun -sdk macosx --show-sdk-path,这会让shell把整个字符串当作静态路径,而不是执行该命令获取真实的SDK路径。链接器找不到对应路径下的库,自然报错。

  2. -l System的格式错误
    链接器的库引用格式是-l<库名>,中间不能加空格,空格会让System被解析成单独的命令参数,而非库名的一部分。


修正后的链接命令

使用反引号`或$()让shell执行xcrun命令,同时修正-lSystem的格式:

# 写法1:反引号
ld hello.o -o hello -lSystem -syslibroot `xcrun -sdk macosx --show-sdk-path` -e _main -arch arm64

# 写法2:$()(更推荐,现代shell兼容性更好)
ld hello.o -o hello -lSystem -syslibroot $(xcrun -sdk macosx --show-sdk-path) -e _main -arch arm64

确认macOS SDK中libSystem的位置

你需要的macOS平台libSystem.dylib确实在macOS SDK目录下,对应路径是:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/lib/libSystem.dylib

只要链接命令正确解析了SDK路径,链接器会自动在该路径下查找库文件,无需手动指定。

额外排查步骤

  • 验证Xcode命令行工具配置:执行xcrun -sdk macosx --show-sdk-path确认输出正确,若有问题,运行sudo xcode-select -s /Applications/Xcode.app/Contents/Developer切换到Xcode内置的命令行工具。
  • 确认汇编代码的入口符号:Apple Silicon平台的macOS程序入口需要下划线前缀,即_main,确保你的汇编源文件中入口符号正确。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 23:17:25