[FFmpeg-user] how to build ffmpeg into one static program without any dependent dynamic library

Moritz Barsnick barsnick at gmx.net
Mon Jul 9 12:39:30 EEST 2018

On Mon, Jul 09, 2018 at 16:21:40 +0800, qw wrote:
> /export/qiang/buildDir/jdcloud_vod_ffmpeg/JD_FFmpeg/libavformat/rtpproto.c:140: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

Yes, that's a restriction of glibc and static linking, google it.

> However, ffmpeg is static without any dependent dynamic library.

Congrats! You did it!

> If I want to use Intel qsv codec, the option of '--enable-libmfx' should be added. Then configure will report error :
> /bin/ld: cannot find -lva
> /bin/ld: cannot find -lva-drm
> The reason why it fails is that, there is no static libva library.

Perhaps you can build these statically yourself (as was recommended for
all the other dependant stuff).

> Can I specify which static libraries are used and which dynamic libraries are used to build ffmpeg?

If both static and dynamic libraries are found, the linkers will by
default prefer the dynamic one.

Choices can be manipulated, but no build system I know of supports
this, because it would make ./configure and the Makefiles too

What comes to mind:
a) Build a fake chroot build environment, where you hide all the
dynamic libraries.

b) At least GNU ld allows you to specify the preference per library on
the command line. From the build, you take the linker command line
(which you observe with "make V=1"). Replace stuff like this:

Or, you can also add stuff before each and every explicitly specified lib:
$ gcc -o something [...] -Wl,-Bdynamic -ltiff -Wl,-Bstatic -lpng [...]

You can also do this in blocks: after "-Wl,-Bdynamic", list all the one
you want dynamically, then add "-Wl,-Bstatic" and list all the ones you
want statically.


More information about the ffmpeg-user mailing list