Ardatr
Ardatr

Reputation: 121

C Code Using FFmpeg libraries - Compilation Error

I've been recently trying to compile C code that uses the FFmpeg libraries; however, the compilation fails due to a reason that I cannot determine.

The code that I've been trying to compile is the filtering_audio.c file on the Doxygen Documentation website for FFmpeg (I'll provide the link, since the code is too long to quote here): http://ffmpeg.org/doxygen/trunk/doc_2examples_2filtering_audio_8c-example.html

I use gcc to compile the code:

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

And I get the following undefined reference errors:

    /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

I understand that the undefined reference error indicates that it wasn't able to find the functions referenced from filtering_audio.c, but this doesn't make sense, since these functions should exist in the FFmpeg libraries.

Any help is appreciated, thank you!

Upvotes: 2

Views: 2776

Answers (2)

user2654836
user2654836

Reputation: 11

I had that same problem and as you said, it doesn't make sense since they are in the very libraries you already added, but it seems the order in which you add the libraries causes errors. As funny as that, so I would suggest to add the lavutil before lavfilter.

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

Upvotes: 0

Carl Norum
Carl Norum

Reputation: 224864

  1. Those aren't compiler errors, they're linker errors.
  2. The errors mean you aren't linking with a library you should be. You're using -lavformat -lavcodec -lavfilter -lavutil now, are you sure that's complete and that you're linking against the versions you want to be?

Edit:

I did a quick test with that example here, and I needed a big list of libraries:

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

Upvotes: 2

Related Questions