I want to build a statically linked executable statically linked to libavcodec and libavformat. The static ffmpeg library was build with:
./configure --enable-static --enable-gpl --enable-nonfree --disable-vaapi
--disable-libopus --prefix=myBuild --disable-swresample
The linkers are set 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 ONLY ONE error message >:-/
src/ffmpeg/myProgram.cpp:115: error: undefined reference to 'avcodec_alloc_context'
Output of 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 include libavcodec.h with extern "C" {} and I believe my static linker order is correct. Why do I get this error? Is it because this method has been deprecated? How can I solve this?
SOLUTION:
Dont use
avCtx = avcodec_alloc_context()
from maybe 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)