bug-gnulib
[Top][All Lists]
Advanced

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

Re: automake conditional for visibility?


From: Bruno Haible
Subject: Re: automake conditional for visibility?
Date: Tue, 3 Mar 2009 23:34:10 +0100
User-agent: KMail/1.9.9

Hi Simon,

> this part of the documentation for the "visibility" module
> appears to assume that all public header files are generated from *.in
> files via autoconf:

Sure. That's the easiest way to ensure that an installed header file is
self-contained.

>    Define a macro specific to your library like this.
>    @smallexample
>    #if @@HAVE_VISIBILITY@@ && BUILDING_LIBFOO
>    #define LIBFOO_DLL_EXPORTED __attribute__((__visibility__("default")))
>    #else
>    #define LIBFOO_DLL_EXPORTED
>    #endif
>    @end smallexample
>    This macro should be enabled in all public header files of your library.
> 
> How about adding a automake conditional?  That would allow adding the
> -DBUILDING_LIBFOO only when visibility is supported, like this:
> 
> if HAVE_VISIBILITY
> AM_CPPFLAGS += -DBUILDING_LIBFOO
> endif

If you read further down, you will read that more complete support of native
Windows platform requires an idiom like this:

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

Here, BUILDING_LIBFOO is also used when HAVE_VISIBILITY is not defined.
So, your simplification works only in the simple case, but not in a more
general setting.

But the essence of your remark is right: there is no need for the public
header files to be generated from .in files. I'm applying the doc patch
below.

> Btw, to encourage namespace clean header files, I would prefer
> LIBFOO_BUILDING.

'BUILDING_LIBFOO' is namespace clean as well. Unrelated packages will not
define a symbol ending in 'LIBFOO'.


2009-03-03  Bruno Haible  <address@hidden>

        * doc/visibility.texi: Recommend to use HAVE_VISIBILITY as a C macro.
        Reported by Simon Josefsson.

        * doc/ld-version-script.texi: Update node reference.

--- doc/visibility.texi.orig    2009-03-03 23:30:31.000000000 +0100
+++ doc/visibility.texi 2009-03-03 23:25:45.000000000 +0100
@@ -102,7 +102,7 @@
 The gnulib autoconf macro @code{gl_VISIBILITY} tests for GCC 4.0 or newer.
 It defines a Makefile variable @code{@@CFLAG_VISIBILITY@@} containing
 @samp{-fvisibility=hidden} or nothing. It also defines as a C macro and
-as a Makefile variable: @@HAVE_VISIBILITY@@. Its value is 1 when symbol
+as a substituted variable: @@HAVE_VISIBILITY@@. Its value is 1 when symbol
 visibility control is supported, and 0 otherwise.
 
 To use this module in a library, say libfoo, you will do these steps:
@@ -120,7 +120,7 @@
 @item
 Define a macro specific to your library like this.
 @smallexample
-#if @@HAVE_VISIBILITY@@ && BUILDING_LIBFOO
+#if BUILDING_LIBFOO && HAVE_VISIBILITY
 #define LIBFOO_DLL_EXPORTED __attribute__((__visibility__("default")))
 #else
 #define LIBFOO_DLL_EXPORTED
@@ -148,9 +148,9 @@
 Note about other compilers: MSVC support can be added easily, by extending
 the definition of the macro mentioned above, to something like this:
 @smallexample
-#if @@HAVE_VISIBILITY@@ && BUILDING_LIBFOO
+#if BUILDING_LIBFOO && HAVE_VISIBILITY
 #define LIBFOO_DLL_EXPORTED __attribute__((__visibility__("default")))
-#elif defined _MSC_VER && BUILDING_LIBFOO
+#elif BUILDING_LIBFOO && defined _MSC_VER
 #define LIBFOO_DLL_EXPORTED __declspec(dllexport)
 #elif defined _MSC_VER
 #define LIBFOO_DLL_EXPORTED __declspec(dllimport)
--- doc/ld-version-script.texi.orig     2009-03-03 23:30:31.000000000 +0100
+++ doc/ld-version-script.texi  2009-03-03 23:29:36.000000000 +0100
@@ -74,4 +74,4 @@
 
 For more discussions about symbol visibility, rather than shared
 library versioning, see the @code{visibility} module
-(@pxref{visibility}).
+(@pxref{Exported Symbols of Shared Libraries}).




reply via email to

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