Search code examples
ffmpegg++static-librariesstatic-linking

How to correctly link ffmpeg to static build "g++ -static"?


I want to link a static build of ffmpeg when compiling a project to a static executable. I use the following command:

g++ -O2 -static -o myBin myBin-myBin.o -lm -lpthread someotherlibraries.a 
/path/to/libavformat.a /path/to/libavcodec.a

but get the following list of errors, although I configured ffmpeg with --disable-libopus:

libavcodec/opusdec.c:376: error: undefined reference to 'swr_is_initialized'
libavcodec/opusdec.c:222: error: undefined reference to 'swr_is_initialized'
libavcodec/opusdec.c:163: error: undefined reference to 'swr_init'
libavcodec/opusdec.c:169: error: undefined reference to 'swr_convert'
libavcodec/opusdec.c:236: error: undefined reference to 'swr_convert'
libavcodec/opusdec.c:117: error: undefined reference to 'swr_convert'
libavcodec/opusdec.c:408: error: undefined reference to 'swr_close'
libavcodec/opusdec.c:557: error: undefined reference to 'swr_close'
libavcodec/opusdec.c:579: error: undefined reference to 'swr_free'
libavcodec/opusdec.c:629: error: undefined reference to 'swr_alloc'

What am I doing wrong here?


Solution

  • you have to set additional linkers soch as -lz for a static build. But why don't just linking dynamically if that works?