From: Bruno Haible Date: Thu, 7 Sep 2023 00:20:05 +0000 (+0200) Subject: doc: Refine documentation of MSVC support for shared libraries. X-Git-Tag: v1.0~809 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=94746b7b9b65c69902a65aea83ebd6b386b24d2b;p=gnulib.git doc: Refine documentation of MSVC support for shared libraries. * doc/lib-symbol-visibility.texi (Exported Symbols of Shared Libraries): Recommend to define BUILDING_SHARED as an Autoconf variable. Recommend to test DLL_EXPORT. --- diff --git a/ChangeLog b/ChangeLog index 2c211265d9..3d2ee1effc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-09-06 Bruno Haible + + doc: Refine documentation of MSVC support for shared libraries. + * doc/lib-symbol-visibility.texi (Exported Symbols of Shared Libraries): + Recommend to define BUILDING_SHARED as an Autoconf variable. Recommend + to test DLL_EXPORT. + 2023-09-06 Bruno Haible doc: Fix syntax error (regression 2023-09-03). diff --git a/doc/lib-symbol-visibility.texi b/doc/lib-symbol-visibility.texi index be5e0863fc..5a3b3cdbfb 100644 --- a/doc/lib-symbol-visibility.texi +++ b/doc/lib-symbol-visibility.texi @@ -140,9 +140,9 @@ for the compilation of the sources that make up the library. Define a macro specific to your library like this. @smallexample #if HAVE_VISIBILITY && BUILDING_LIBFOO -#define LIBFOO_DLL_EXPORTED __attribute__((__visibility__("default"))) +# define LIBFOO_DLL_EXPORTED __attribute__((__visibility__("default"))) #else -#define LIBFOO_DLL_EXPORTED +# define LIBFOO_DLL_EXPORTED #endif @end smallexample This macro should be enabled in all public header files of your library. @@ -168,27 +168,35 @@ 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 -#define LIBFOO_DLL_EXPORTED __attribute__((__visibility__("default"))) -#elif (defined _WIN32 && !defined __CYGWIN__) && BUILDING_SHARED && BUILDING_LIBFOO -#define LIBFOO_DLL_EXPORTED __declspec(dllexport) -#elif (defined _WIN32 && !defined __CYGWIN__) && BUILDING_SHARED -#define LIBFOO_DLL_EXPORTED __declspec(dllimport) +# define LIBFOO_DLL_EXPORTED __attribute__((__visibility__("default"))) +#elif (defined _WIN32 && !defined __CYGWIN__) && @@BUILDING_SHARED@@ && BUILDING_LIBFOO +# if defined DLL_EXPORT +# define LIBFOO_DLL_EXPORTED __declspec(dllexport) +# else +# define LIBFOO_DLL_EXPORTED +# endif +#elif (defined _WIN32 && !defined __CYGWIN__) && @@BUILDING_SHARED@@ +# define LIBFOO_DLL_EXPORTED __declspec(dllimport) #else -#define LIBFOO_DLL_EXPORTED +# 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}, +Here @code{BUILDING_SHARED} is an Autoconf variable 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}. You may use the following @samp{configure.ac} snippet: @smallexample if test "$enable_shared" = yes; then - building_shared=1 + BUILDING_SHARED=1 else - building_shared=0 + BUILDING_SHARED=0 fi - AC_DEFINE_UNQUOTED([BUILDING_SHARED], [$building_shared], - [Define when --enable-shared is used.]) + AC_SUBST([BUILDING_SHARED]) @end smallexample + +@noindent +And @code{DLL_EXPORT} is defined by Libtool, on Windows platforms, when +compiling for a DLL. It is not defined when Libtool compiles an object +file meant to be linked statically into some executable.