Let’s say you come across a scenario where you have to compile a libav based program like one here: https://github.com/libav/libav/blob/master/doc/examples/decode_video.c
Obviously this can be compiled with make script inside examples folder. Lets say we want to create a custom program outside of all these and just use libav headers and libav static libs to build our program to the final output application, we have to give the dependency of libav libraries properly in order to get it compiled.
the dependency tree is roughly
libavformat –depends-on–> libavcodec –depends-on–> libavresample –depends-on–> libavutil
So if you have a file X.c and set of all libav static libs like libavcodec.a, libavformat.a, libavutil.a etc and want to compile that you have to link the libav properly in order for your application file to compile. The final compilation that works is as given below. Here the input file is demux_decode.c and output is video_decoder.
gcc -I./ -L./libavcodec/ -L./libavformat/ -L./libavutil/ -L./libavdevice -L./libswscale/ -L./libavfilter/ -L./libavresample/ demux_decode.c -l:libavdevice.a -l:libavfilter.a -l:libavformat.a -l:libavcodec.a -l:libswscale.a -l:libavresample.a -l:libavutil.a -lm -lpthread -o video_decoder
Note the order of “-l” linker options above. It has to be the same when you want to compile your custom program.