Ffmpeg - compilation problem with g ++

I am trying to run a program that uses ffmpeg libraries to decode an mp3 file. I use the following options to compile the program:

g++ -c play.cpp -o play.o g++ -o play play.o -L/usr/local/lib -lavutil -lavcodec -lavformat -lavdevice \ -lavfilter -ldl -lasound -L/usr/lib -lSDL -lpthread -lz -lswscale -lm 

But when binding, I get the following errors:

 play.cpp:(.text+0x49): undefined reference to `av_dup_packet(AVPacket*)' play.cpp:(.text+0x66): undefined reference to `av_malloc(unsigned int)' play.cpp:(.text+0x324): undefined reference to `avcodec_decode_audio3(AVCodecContext*, short*, int*, AVPacket*)' play.cpp:(.text+0x387): undefined reference to `av_free_packet(AVPacket*)' 

and so on ... These reported functions are available in libavcodec.a, etc., which I have already indicated with link parameters. Can someone please tell me what might be wrong here, or suggest how to approach debugging?

+2
source share
2 answers

Is this your own program, not a standard libav example? Maybe I'm wrong, but if so, you can probably forget to specify extern "C", including the libav headers:

 extern "C" { #include <avcodec.h> #include <avformat.h> } 

This may be a problem "if you are trying to compile sources with a C ++ compiler and libav (ffmpeg) is compiled using the C compiler, so you should mark the library headers compiled by the C compiler using extern C.

If you already mark as extern C already, send some of the code from your program to see ..

+6
source

You must make sure that the correct version of -lavcodec selected with verbose linkin ( -Wl,--verbose ) and check with objdump or ldd if the characters are actually in the library.

You can try to switch the order of the -l flags, this is very important; however, since play.cpp contains function references in -lavcodec , the flag order should already be right.

+1
source

All Articles