bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Documentation module lib-symbol-visibility


From: Michael Goffioul
Subject: Re: Documentation module lib-symbol-visibility
Date: Fri, 20 Jul 2012 14:34:26 +0100

On Fri, Jul 20, 2012 at 2:17 PM, Дилян Палаузов <address@hidden> wrote:
Hello Michael,

there is a point with dllexport/dllimport, however when not building for Windows, the argumentation does not apply and the recommendation for use LIBFOO_DLL_EXPORTED in the header files is suboptimal in my eyes.

Indeed, when you don't care about compatibility with MSVC, you don't need to put the decorators into the headers. OTOH if you care about compatibility with MSVC, then decorators are needed in the headers, at least for variables (including class static variables).
 

Looking at the documentation of module lib-symbol-visibility, at the very end, I might oversee something, but I have the feeling, that when ./configure determined support for -fvisibility=hidden, and BUILDING_LIBFOO, HAVE_VISIBILITY and _MSC_VER are all defined, from

     #if BUILDING_LIBFOO && HAVE_VISIBILITY
     #define LIBFOO_DLL_EXPORTED __attribute__((__visibility__("default")))
     #elif BUILDING_LIBFOO && defined _MSC_VER
     #define LIBFOO_DLL_EXPORTED __declspec(dllexport)
     #elif defined _MSC_VER
     #define LIBFOO_DLL_EXPORTED __declspec(dllimport)
     #else
     #define LIBFOO_DLL_EXPORTED
     #endif

follows, that LIBFOO_DLL_EXPORTED is
   __attribute__((__visibility__("default")))
whereas it shall be
  declspec(dllexport)
as declspec(dllexport) implies visibility(default), and visibility(default) does not help to DLL-export the symbols.

The problem is not at export time, it's at import time, for client code using the headers. A DLL-exported variable that is not decorated with dllimport (from the client code point of view) will result in undefined reference at link stage. By decorating variables (and more generally functions) in the headers, you can achieve MSVC compatibility with little efforts, with the CPP snippet above. But again, this only applies when you care about compatibility. 

Michael.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]