Undefined reference to avcodec_alloc_context, but the correct ffmpeg linker order?

I want to create a statically linked executable statically linked to libavcodec and libavformat. The ffmpeg static library was built with:

./configure --enable-static --enable-gpl --enable-nonfree --disable-vaapi --disable-libopus --prefix=myBuild --disable-swresample 

Linkers are installed as follows:

 g++ -O2 -static -o myBin myBin-myBin.o someotherlibraries.a -L/ffmpeg/myBuild/lib -lavformat -lavcodec -lavutil -lrt -lm -lpthread -lz 

When compiling, I get the message ONLY ONE : - /

 src/ffmpeg/myProgram.cpp:115: error: undefined reference to 'avcodec_alloc_context' 

Output signal nm / ffmpeg / myBuild / lib / libavcodec.a | grep avcodec_alloc_context:

  U avcodec_alloc_context3 U avcodec_alloc_context3 000003c0 T avcodec_alloc_context3 U avcodec_alloc_context3 

I enable libavcodec.h with extern "C" {} and I believe my static linker order is correct. Why am I getting this error? Is it because this method is deprecated? How can i solve this?

DECISION:

Do not use

 avCtx = avcodec_alloc_context() 

from older code snippets but use

 codec = avcodec_find_decoder(CODEC_ID_XYZ);//for completeness but should be the same as before avCtx = avcodec_alloc_context3(codec) 
+7
c ++ ffmpeg libavcodec libavformat static-linking
source share
2 answers

Instead, you tried to call avcodec_alloc_context3?

I have no problem calling avcodec_alloc_context3, highlight extradata and call avcodec_open2.

Also the link order should be -lavutil -lavformat -lavcodec

+6
source share

if I remember correctly, we also had problems with this, and the solution was that you need to specifically add libavcodec.a (along with the full path) and other ffmpeg static libraries to the g ++ linking step. See if this works like that.

In addition, the order of the libraries is important. I no longer have old masters, but perhaps remember that libavutil should be the first on the list.

So your bind command should look something like this:

 g++ -O2 -static -o myBin myBin-myBin.o someotherlibraries.a /ffmpeg/myBuild/lib/libavutil.a /ffmpeg/myBuild/lib/libavformat.a /ffmpeg/myBuild/lib/libavcodec.a -lrt -lm -lpthread -lz 
+2
source share

All Articles