【问题标题】:libav - undefined reference to 'av_frame_alloc' and morelibav - 对“av_frame_alloc”等的未定义引用
【发布时间】:2015-11-07 07:59:51
【问题描述】:

我正在尝试从 libav 文档编译本教程:link

我没有改变代码!

但是当我编译它时:

gcc test.c -lavformat -lswscale -lavdevice -lavformat -lavcodec -lavutil -lpthread -lm -o example

我收到以下错误:

undefined reference to `check_sample_fmt'
undefined reference to `select_sample_rate'
undefined reference to `select_channel_layout'
undefined reference to `av_frame_alloc'
undefined reference to `av_frame_free'

搜索 Dr.google 我读到它可能与库的链接顺序有关。但是我还没有找到正确的?!

编辑: 这个“可能重复”似乎与我的问题无关

【问题讨论】:

  • 谢谢Dayal,我已经看过那个话题了!但不要认为这与我的问题有关
  • 我也试过这个命令: gcc -o example test.c -lavformat -lavcodec -lavutil -lswscale -lfdk-aac -lao -lavdevice -lavresample -lpthread -lm 现在我只有 undefined参考“av_frame_alloc 和 av_frame_free”
  • 您确定需要链接所有这些库吗?该示例程序仅使用gcc test.c -lavutil -lm -lavcodec -o example 对我来说编译得很好
  • 谢谢@szx,遗憾的是我仍然得到一些未定义的参考错误。也许这会有所帮助。我正在使用带有 ./configure --disable-shared --enable-static 的 libav(11.4) 我从 doc 文件夹中的示例中复制了“音频解码”的示例代码。这是我发布的示例的较新版本(我只能在网上找到这个旧版本)

标签: c ffmpeg libavcodec libav libavformat


【解决方案1】:

ffmpeg 带有一个用于示例的 Makefile。我拿了这个,只是将它用于我的 libav 示例。 Link

【讨论】:

    【解决方案2】:

    您可能正在使用较新版本的 FFmpeg 运行旧代码。 Ffmpeg 更改了一些函数名称,一些会产生一些贬值的警告,而另一些则会产生错误。

    据官方Ffmpeg github

    av_frame_alloc(), av_frame_unref() and av_frame_free() now can and should be 
    used instead of avcodec_alloc_frame(), avcodec_get_frame_defaults() and avcodec_free_frame() respectively
    

    【讨论】:

      【解决方案3】:

      这不适用于您的情况,但如果您尝试使用 C++ 中的 ffmpeg,您会遇到类似的问题。

      #include <libavcodec/avcodec.h>
      
      int main() {
        av_frame_alloc();
      }
      

      不幸的是,ffmpeg 标头没有正确的 extern "C" { 包装器,因此您必须自己做。

      extern "C" {
      #include <libavcodec/avcodec.h>
      }
      
      int main() {
        av_frame_alloc();
      }
      

      【讨论】:

        猜你喜欢
        • 2014-07-26
        • 2013-03-15
        • 2013-10-26
        • 2013-02-17
        • 2014-01-10
        • 2015-03-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多