使用FFmpeg库的C代码 - 编译错误

时间:2013-06-02 17:22:06

标签: c gcc compilation ffmpeg

我最近一直在尝试编译使用FFmpeg库的C代码;但是,由于我无法确定的原因,编译失败了。

我一直在尝试编译的代码是Doxygen文档网站上针对FFmpeg的filtering_audio.c文件(我将提供链接,因为代码太长而无法引用):http://ffmpeg.org/doxygen/trunk/doc_2examples_2filtering_audio_8c-example.html

我使用gcc编译代码:

    gcc filter.c -lavformat -lavcodec -lavfilter  -lavutil

我得到以下未定义的引用错误:

    /tmp/cc90K2S5.o: In function `init_filters':
    filter.c:(.text+0x3e5): undefined reference to `av_int_list_length_for_size'
    filter.c:(.text+0x407): undefined reference to `av_int_list_length_for_size'
    filter.c:(.text+0x42d): undefined reference to `av_opt_set_bin'
    filter.c:(.text+0x482): undefined reference to `av_int_list_length_for_size'
    filter.c:(.text+0x4a4): undefined reference to `av_int_list_length_for_size'
    filter.c:(.text+0x4ca): undefined reference to `av_opt_set_bin'
    filter.c:(.text+0x51f): undefined reference to `av_int_list_length_for_size'
    filter.c:(.text+0x541): undefined reference to `av_int_list_length_for_size'
    filter.c:(.text+0x567): undefined reference to `av_opt_set_bin'
    /tmp/cc90K2S5.o: In function `print_frame':
    filter.c:(.text+0x76b): undefined reference to `av_frame_get_channel_layout'
    /tmp/cc90K2S5.o: In function `main':
    filter.c:(.text+0x831): undefined reference to `av_frame_alloc'
    filter.c:(.text+0x83d): undefined reference to `av_frame_alloc'
    filter.c:(.text+0x9de): undefined reference to `av_buffersrc_add_frame_flags'
    filter.c:(.text+0xa16): undefined reference to `av_buffersink_get_frame'
    filter.c:(.text+0xa58): undefined reference to `av_frame_unref'
    filter.c:(.text+0xab6): undefined reference to `av_frame_free'
    filter.c:(.text+0xac5): undefined reference to `av_frame_free'
    collect2: error: ld returned 1 exit status

我知道未定义的引用错误表明它无法找到filtering_audio.c引用的函数,但这没有意义,因为这些函数应存在于FFmpeg库中。

感谢任何帮助,谢谢!

2 个答案:

答案 0 :(得分:2)

  1. 这些不是编译器错误,它们是链接器错误。
  2. 错误意味着您没有链接到应该是的库。您现在正在使用-lavformat -lavcodec -lavfilter -lavutil,是否确定已完成并且您要链接到您想要的版本?
  3. 编辑:

    我在这里做了一个快速测试,我需要一个库列表:

    -lavformat
    -lavcodec
    -lavfilter
    -lavutil
    -lswresample
    -lswscale
    -lz
    -lbz2
    

答案 1 :(得分:0)

我有同样的问题,正如你所说,它没有意义,因为它们在你已经添加的库中,但似乎你添加库的顺序会导致错误。这很有趣,所以我建议在lavfilter之前添加lavutil。

Why does the order in which libraries are linked sometimes cause errors in GCC?