Opened 6 years ago

Last modified 6 years ago

#7396 reopened defect

libavcodec: uses dynamic libx264 by default

Reported by: maarten Owned by:
Priority: minor Component: avcodec
Version: git-master Keywords: libx264
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
Linking ffmpeg to static libx264 causes LNK4049 warnings (on Windows, Visual Studio)

On Windows Visual Studio, when linking a static ffmpeg build to static dependencies, libavcodec assumes that libx264 is dynamic.

How to reproduce:
Build a static libx264 library.
Build a dynamic ffmpeg library, with libx264 support.

OR

Build static libx264, build static ffmpeg library, link an application to both static libraries.

Following warnings are produces:

libavcodec.lib(libx264.o) : warning LNK4049: locally defined symbol x264_levels imported [C:\issues\conan_ffmpeg_1\build\issue.vcxproj]
libavcodec.lib(libx264.o) : warning LNK4049: locally defined symbol x264_bit_depth imported [C:\issues\conan_ffmpeg_1\build\issue.vcxproj]

I believe the following lines in libavcodec/libx264.c are to blame and should be removed.

#if defined(_MSC_VER)
#define X264_API_IMPORTS 1
#endif

Change History (7)

comment:1 by Carl Eugen Hoyos, 6 years ago

Resolution: invalid
Status: newclosed

The described behaviour is a property of your toolchain.

comment:2 by Hendrik, 6 years ago

The message is just a warning with minimal consequences. Without that define, linking of a dynamic library would not work, while with a static library it only results in a warning.

Unfortunately avcodec does not necessarily know if its going to link against a shared or static libx264.

Last edited 6 years ago by Hendrik (previous) (diff)

comment:3 by maarten, 6 years ago

I understand that.
That's why people building ffmpeg need to pass CFLAGS=-DX264_API_IMPORTS=1 or something similar to configure.

comment:4 by maarten, 6 years ago

Last edited 6 years ago by maarten (previous) (diff)

comment:5 by Hendrik, 6 years ago

Or they don't, and you just ignore a mostly meaningless warning. :)

comment:6 by maarten, 6 years ago

Why is this flag only defined for x264 and x265?

Other dependencies such as freetype, libpng, opus, ogg, zmq, sdl2, vpx, ... can also be either static or dynamic and do not have something defined.

Those dependencies have a pkg-config file that will automatically set the appropriate flags.

Warnings obscure potential bugs and should be eradicated when possible.

comment:7 by Carl Eugen Hoyos, 6 years ago

Component: undeterminedavcodec
Keywords: libx264 added
Priority: normalminor
Resolution: invalid
Status: closedreopened
Version: unspecifiedgit-master
Note: See TracTickets for help on using tickets.