Opened 12 months ago

Last modified 12 months 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 Changed 12 months ago by cehoyos

  • Resolution set to invalid
  • Status changed from new to closed

The described behaviour is a property of your toolchain.

comment:2 Changed 12 months ago by heleppkes

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 12 months ago by heleppkes (previous) (diff)

comment:3 Changed 12 months ago by maarten

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

comment:4 Changed 12 months ago by maarten

Last edited 12 months ago by maarten (previous) (diff)

comment:5 Changed 12 months ago by heleppkes

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

comment:6 Changed 12 months ago by maarten

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 Changed 12 months ago by cehoyos

  • Component changed from undetermined to avcodec
  • Keywords libx264 added
  • Priority changed from normal to minor
  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Version changed from unspecified to git-master
Note: See TracTickets for help on using tickets.