user2212461
user2212461

Reputation: 3263

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?

Upvotes: 3

Views: 3333

Answers (2)

user2212461
user2212461

Reputation: 3263

-lswresample was the missing flag that caused the error

Upvotes: 2

user3521269
user3521269

Reputation: 458

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

Upvotes: 1

Related Questions