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

M1 Mac编译FFmpeg报错:macOS-arm64无法链接同架构静态库

M1 Mac编译FFmpeg时静态库链接失败问题解决

问题表现

编译FFmpeg的链接阶段,ld抛出如下警告,最终链接失败:

ld: warning: ignoring file libavdevice/libavdevice.a, building for macOS-arm64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file libavfilter/libavfilter.a, building for macOS-arm64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file libswresample/libswresample.a, building for macOS-arm64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file libswscale/libswscale.a, building for macOS-arm64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file libavutil/libavutil.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
ld: warning: ignoring file libpostproc/libpostproc.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
ld: warning: ignoring file libavformat/libavformat.a, building for macOS-arm64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file libavcodec/libavcodec.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )

从报错信息看存在两个矛盾点:

  • 构建目标为macOS-arm64,被忽略的静态库也标注为macOS-arm64架构,同架构静态库无法被正常链接
  • 部分静态库被识别为不支持的文件格式,文件头魔数为0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A
    本次编译使用的设备为M1款MacBook,使用的configure配置参数如下:
../configure --cc=/usr/bin/clang --prefix=/opt/ffmpeg --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librubberband  --enable-libwebp --enable-libx264 --enable-libx265  --enable-libzimg --enable-libzmq  --enable-version3 --pkg-config-flags=--static --disable-ffplay --extra-cflags="-I/opt/homebrew/include" --extra-cxxflags="-I/opt/homebrew/include" --extra-ldflags="-L/opt/homebrew/lib"

故障原因

报错里的文件头魔数0x21 0x3C 0x61 0x72 0x63 0x68 0x3E转成ASCII字符是!<arch>,是llvm-ar生成的静态库归档文件的标准头,正常情况下macOS的ld可以识别该格式。
出现这个矛盾报错的核心原因是编译目录残留了之前编译生成的损坏/架构混杂的中间静态库文件:如果之前在同一份源码目录下编译过其他架构(比如x86_64)的版本,或者之前编译过程异常中断留下了归档索引损坏的.a文件,ld读取这些异常文件时,要么无法识别文件格式抛出格式错误,要么读取到混杂的架构信息,错误抛出“同架构无法链接”的矛盾提示。

解决步骤

  • 全量清理所有编译中间产物:在FFmpeg源码根目录执行清理命令,如果是单独创建build目录编译的,直接删除整个build目录
make clean
make distclean
  • 校验Homebrew安装的所有依赖库架构,确保都是arm64版本
file /opt/homebrew/lib/*.a | grep -v arm64

如果命令输出存在非arm64架构的静态库,重新安装对应的Homebrew包即可。

  • 确认当前终端运行在原生arm64模式下,执行arch命令校验,输出结果为arm64才可以继续编译,不要在Rosetta转译模式的终端下执行编译操作。
  • 新建干净的编译目录,重新执行configure和编译命令即可
mkdir build && cd build
# 粘贴原有configure命令
../configure --cc=/usr/bin/clang --prefix=/opt/ffmpeg --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librubberband  --enable-libwebp --enable-libx264 --enable-libx265  --enable-libzimg --enable-libzmq  --enable-version3 --pkg-config-flags=--static --disable-ffplay --extra-cflags="-I/opt/homebrew/include" --extra-cxxflags="-I/opt/homebrew/include" --extra-ldflags="-L/opt/homebrew/lib"
make -j$(sysctl -n hw.ncpu)
sudo make install

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.03 10:31:02