diff options
Diffstat (limited to 'woe32dll/export.h')
| -rw-r--r-- | woe32dll/export.h | 49 | 
1 files changed, 35 insertions, 14 deletions
diff --git a/woe32dll/export.h b/woe32dll/export.h index 999b21b8..ffcb7ab3 100644 --- a/woe32dll/export.h +++ b/woe32dll/export.h @@ -1,5 +1,5 @@  /* Exporting symbols from Windows shared libraries. -   Copyright (C) 2006, 2011-2023 Free Software Foundation, Inc. +   Copyright (C) 2006, 2011-2025 Free Software Foundation, Inc.     Written by Bruno Haible <bruno@clisp.org>, 2006.     This program is free software: you can redistribute it and/or @@ -24,7 +24,15 @@     You should have received a copy of the GNU Lesser General Public License     along with this program.  If not, see <https://www.gnu.org/licenses/>.  */ -/* There are four ways to build shared libraries on Windows: +/* Two things are complicated when dealing with shared libraries on Windows: +     - Exporting symbols from shared libraries (→ 'dllexport'), +     - Referencing symbols in shared libraries from outside the library +       (→ 'dllimport'). +   Without GNU libtool, the complications apply to both functions and variables. +   With GNU libtool, the complications apply to variables only; GNU libtool +   deals with the functions. + +   There are four ways to build shared libraries on Windows:     - Export only functions, no variables.       This has the drawback of severely affecting the programming style in use. @@ -60,15 +68,28 @@         1. the header files are unique to this library (not shared with            other packages), and         2. the library sources are contained in one directory, making it easy -          to define a -DBUILDING_LIBXYZ flag for the library. +          to define a -DBUILDING_LIBXYZ flag for the library (either in +          AM_CPPFLAGS or in libxyz_la_CPPFLAGS).       Example: -         #ifdef BUILDING_LIBICONV -         #define LIBICONV_SHLIB_EXPORTED __declspec(dllexport) -         #else -         #define LIBICONV_SHLIB_EXPORTED __declspec(dllimport) +         #if (defined _WIN32 || defined __CYGWIN__) && WOE32DLL +                                             // on Windows, with --enable-shared +         # if BUILDING_LIBXYZ                // building code for libxyz +         #  if defined DLL_EXPORT            // compiling object files for a DLL +         #   define LIBXYZ_SHLIB_EXPORTED __declspec(dllexport) +         #  else                             // compiling static object files +         #   define LIBXYZ_SHLIB_EXPORTED +         #  endif +         # else                              // building code outside libxyz +         #  define LIBXYZ_SHLIB_EXPORTED __declspec(dllimport) +         # endif +         #else                               // not Windows, or --disable-shared +         # define LIBXYZ_SHLIB_EXPORTED           #endif -     We use this technique for the libintl and the libiconv libraries. +     We use this technique for +       - libiconv, +       - libintl, +       - libgettextlib and libgettextsrc.     - Define a macro that expands to  __declspec(dllimport)  always, and use       it in all header files of the library.  Use an explicit export list for @@ -76,18 +97,18 @@       This is acceptable if         1. the programming language is not C++ (because the name mangling of            static struct/class fields and of variables in namespaces makes it -          hard to maintain an export list). +          hard to maintain an export list), +       2. there are no constructs such as +             extern __declspec (dllimport) int var; +             int * const b = &var; +          or equivalent (e.g. as in gnulib/lib/uninorm/nfc.c), +          because these constructs give a compilation error.       The benefit of this approach is that the partitioning of the source files       into libraries (which source file goes into which library) does not       affect the source code; only the Makefiles reflect it.       The performance loss due to the unnecessary indirection for references       to variables from within the library defining the variable is acceptable. -     We use this technique for libgettextlib (because it contains many gnulib -     modules) and for libgettextsrc (because this makes it easy to move source -     code from an msg* program to libgettextsrc).  The macro is called -     DLL_VARIABLE. -     This file allows building an explicit export list.  You can either       - specify the variables to be exported, and use the GNU ld option         --export-all-symbols to export all function names, or  | 
