bug-gnulib
[Top][All Lists]
Advanced

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

Re: New gnulib user !


From: Bruno Haible
Subject: Re: New gnulib user !
Date: Sun, 03 Jul 2022 16:52:29 +0200

Vivien Kraus wrote:
> - The library function export visibility trick is great, but the manual
> suggests to augment it with dllimport/export for MSVC:
> 
> #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
> 
> However, using this as-is breaks for mingw (HAVE_VISIBILITY is 0 and
> _MSC_VER is not defined, so all symbols are exported, which means a
> possible collision with gnulib functions used in both libfoo and a
> program linked to libfoo). Maybe the manual should suggest to extend
> the MSVC check to mingw as well? That’s what I did in my project.

Good point. I'm making this documentation update:


2022-07-03  Bruno Haible  <bruno@clisp.org>

        lib-symbol-visibility: Improve documentation.
        Reported by Vivien Kraus <vivien@planete-kraus.eu> in
        <https://lists.gnu.org/archive/html/bug-gnulib/2022-06/msg00093.html>.
        * doc/lib-symbol-visibility.texi: List the platforms. Extend the
        LIBFOO_DLL_EXPORTED to work also with mingw and also with
        --disable-shared.

diff --git a/doc/lib-symbol-visibility.texi b/doc/lib-symbol-visibility.texi
index 60cde8dae4..9574e439dd 100644
--- a/doc/lib-symbol-visibility.texi
+++ b/doc/lib-symbol-visibility.texi
@@ -106,6 +106,24 @@ It defines a Makefile variable @code{@@CFLAG_VISIBILITY@@} 
containing
 as a substituted variable: @@HAVE_VISIBILITY@@.  Its value is 1 when symbol
 visibility control is supported, and 0 otherwise.
 
+As of 2022, symbol visibility control is supported on
+@itemize @bullet
+@item
+ELF platforms (glibc, Linux, *BSD, Solaris) with GCC or clang,
+@item
+macOS,
+@item
+AIX with gcc or xlclang.
+@end itemize
+@noindent
+It is not supprted on
+@itemize @bullet
+@item
+Other compilers on ELF platforms or AIX,
+@item
+Windows.
+@end itemize
+
 To use this module in a library, say libfoo, you will do these steps:
 
 @enumerate
@@ -121,7 +139,7 @@ for the compilation of the sources that make up the library.
 @item
 Define a macro specific to your library like this.
 @smallexample
-#if BUILDING_LIBFOO && HAVE_VISIBILITY
+#if HAVE_VISIBILITY && BUILDING_LIBFOO
 #define LIBFOO_DLL_EXPORTED __attribute__((__visibility__("default")))
 #else
 #define LIBFOO_DLL_EXPORTED
@@ -149,13 +167,17 @@ your library.
 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 BUILDING_LIBFOO && HAVE_VISIBILITY
+#if HAVE_VISIBILITY && BUILDING_LIBFOO
 #define LIBFOO_DLL_EXPORTED __attribute__((__visibility__("default")))
-#elif BUILDING_LIBFOO && defined _MSC_VER
+#elif (defined _WIN32 && !defined __CYGWIN__) && BUILDING_SHARED && 
BUILDING_LIBFOO
 #define LIBFOO_DLL_EXPORTED __declspec(dllexport)
-#elif defined _MSC_VER
+#elif (defined _WIN32 && !defined __CYGWIN__) && BUILDING_SHARED
 #define LIBFOO_DLL_EXPORTED __declspec(dllimport)
 #else
 #define LIBFOO_DLL_EXPORTED
 #endif
 @end smallexample
+@noindent
+Here @code{BUILDING_SHARED} is a C macro that you have to define.  It
+ought to evaluate to 1 in a build configured with @samp{--enable-shared},
+or to 0 in a build configured with @samp{--disable-shared}.






reply via email to

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