Skip to content

Commit cd894c0

Browse files
committed
Fix static MinGW build
Fixes PCRE2Project#243
1 parent 04fbb65 commit cd894c0

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

src/pcre2posix.h

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,25 +130,44 @@ set, we ensure here that it has no effect. */
130130
#define PCRE2_CALL_CONVENTION
131131
#endif
132132

133-
/* When an application links to a PCRE2 DLL in Windows, the symbols that are
134-
imported have to be identified as such. When building PCRE2, the appropriate
135-
export settings are needed, and are set in pcre2posix.c before including this
136-
file. */
137-
138-
#if defined(_WIN32) && !defined(PCRE2_STATIC) && !defined(PCRE2POSIX_EXP_DECL)
139-
# define PCRE2POSIX_EXP_DECL extern __declspec(dllimport)
140-
# define PCRE2POSIX_EXP_DEFN __declspec(dllimport)
141-
#endif
142-
143-
/* By default, we use the standard "extern" declarations. */
133+
/* When compiling a DLL for Windows, the exported symbols have to be declared
134+
using some MS magic. I found some useful information on this web page:
135+
http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the
136+
information there, using __declspec(dllexport) without "extern" we have a
137+
definition; with "extern" we have a declaration.
138+
We use:
139+
140+
PCRE2_EXP_DECL for declarations
141+
PCRE2_EXP_DEFN for definitions
142+
143+
The reason for wrapping this in #ifndef PCRE2POSIX_EXP_DECL is so that
144+
pcre2test, which is an application, but needs to import this file in order to
145+
"peek" at internals, can #include pcre2posix.h first to get an application's-eye
146+
view.
147+
148+
In principle, people compiling for non-Windows, non-Unix-like (i.e. uncommon,
149+
special-purpose environments) might want to stick other stuff in front of
150+
exported symbols. That's why, in the non-Windows case, we set
151+
PCRE2POSIX_EXP_DEFN only if it is not already set. */
144152

145153
#ifndef PCRE2POSIX_EXP_DECL
146-
# ifdef __cplusplus
147-
# define PCRE2POSIX_EXP_DECL extern "C"
148-
# define PCRE2POSIX_EXP_DEFN extern "C"
154+
# ifdef _WIN32
155+
# ifndef PCRE2_STATIC
156+
# define PCRE2POSIX_EXP_DECL extern __declspec(dllexport)
157+
# define PCRE2POSIX_EXP_DEFN __declspec(dllexport)
158+
# else
159+
# define PCRE2POSIX_EXP_DECL extern
160+
# define PCRE2POSIX_EXP_DEFN
161+
# endif
149162
# else
150-
# define PCRE2POSIX_EXP_DECL extern
151-
# define PCRE2POSIX_EXP_DEFN extern
163+
# ifdef __cplusplus
164+
# define PCRE2POSIX_EXP_DECL extern "C"
165+
# else
166+
# define PCRE2POSIX_EXP_DECL extern
167+
# endif
168+
# ifndef PCRE2POSIX_EXP_DEFN
169+
# define PCRE2POSIX_EXP_DEFN PCRE2POSIX_EXP_DECL
170+
# endif
152171
# endif
153172
#endif
154173

0 commit comments

Comments
 (0)