[FFmpeg-devel] [RFC] Add exported global variables to import libraries for WIN32

Tomas Härdin tomas.hardin
Wed Oct 6 08:58:18 CEST 2010

On Wed, 2010-10-06 at 00:22 -0300, Ramiro Polla wrote:
> On Tue, Oct 5, 2010 at 10:13 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
> > On Fri, Sep 10, 2010 at 04:39:39PM +0200, Tomas H?rdin wrote:
> >> About two months ago I posted a thread
> >> (https://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2010-July/092654.html) regarding importing the global constants libav* export in MSVC (link.exe). Eventually I figured out that importing the globals rather than adding a function would be a better solution. I went with a __declspec(dllimport) solution, which looked OK until M?ns asked whether it'd work on static builds. It didn't.
> >>
> >> After discussing it on IRC we figured out that it can't be solved in the
> >> headers since both static and dynamic libraries might be built at the
> >> same time. It seems that what needs to be done is have the generated
> >
> > building them at the same time implicates that PIC will be used for static
> > libs in some cases while it otherwise would not?
> >
> > If yes then this feature is really retarded as it causes performance loss and
> > likely without the user realizing it.
> It's possible to build win32 shared libraries without PIC.
> I couldn't find a clean way to have dllimport for such data, so I
> added a note to the documentation. I don't think we should care that
> much about this and MSVC since it's a simple one-line change for the
> user and the headers won't work out-of-the box anyways
> (stdint.h/inttypes.h must be installed), so the user already has to go
> through some effort to get it working.

I'm a bit confused - isn't it possible to mark the globals in such a way
that the generated import libraries take care of things? I have
certainly seen DLLs export globals in other cases..

Oh, and editing the headers may not be a desirable solution for all
users (complicates build setup in my case). Something like the following
hack can be used by the user in their code to make it work:

#ifdef WIN32
#define av_pix_fmt_descriptors av_pix_fmt_descriptors_foo

#include <libavutil/pixdesc.h>

#ifdef WIN32
#undef av_pix_fmt_descriptors
__declspec(dllimport) const AVPixFmtDescriptor av_pix_fmt_descriptors[];

Do something similar for whichever global is desired. Not pretty, but
hacks rarely are :)

Oh, and neither that solution nor editing the headers makes it easy to
switch between dynamic and static linking. Maybe not much of a problem

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101006/184109c7/attachment.pgp>

More information about the ffmpeg-devel mailing list