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

ARM架构Mac下clang编译FFmpeg程序遇链接未定义符号问题

问题分析

你遇到的是链接阶段未定义符号错误,核心原因是:你只通过-L/opt/homebrew/lib告诉链接器库文件的搜索路径,但没有明确指定要链接哪些FFmpeg的库文件——头文件让编译器知道函数的声明,而链接器需要找到函数的实现库才能完成编译。

解决方案

FFmpeg的功能被拆分到多个独立库中,使用avformat相关函数需要链接对应的libavformat库,同时它依赖libavutil基础库,修改编译命令如下:

clang datafinder.c -o datafinder -I/opt/homebrew/include -L/opt/homebrew/lib -lavformat -lavutil -v

选项说明

  • -lavformat:链接libavformat.dylib,对应你用到的avformat_open_input、avformat_free_context等函数
  • -lavutil:libavformat依赖的基础工具库,必须一起链接
  • 后续如果用到libavcodec或libswscale的函数,还需要添加-lavcodec、-lswscale
验证库文件

你可以先确认/opt/homebrew/lib下确实存在这些库:

ls /opt/homebrew/lib/libavformat.dylib /opt/homebrew/lib/libavutil.dylib
简化编译的小技巧

为了避免手动写一堆链接选项,也可以用FFmpeg附带的pkg-config工具自动生成编译和链接参数:

clang datafinder.c -o datafinder $(pkg-config --cflags --libs libavformat) -v

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 20:04:58