]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/dlimpexp.h
3 * Purpose: Macros for declaring DLL-imported/exported functions
4 * Author: Vadim Zeitlin
6 * Created: 16.10.2003 (extracted from wx/defs.h)
8 * Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
9 * Licence: wxWindows licence
13 This is a C file, not C++ one, do not use C++ comments here!
16 #ifndef _WX_DLIMPEXP_H_
17 #define _WX_DLIMPEXP_H_
19 #if defined(HAVE_VISIBILITY)
20 # define WXEXPORT __attribute__ ((visibility("default")))
21 # define WXIMPORT __attribute__ ((visibility("default")))
22 #elif defined(__WINDOWS__)
24 __declspec works in BC++ 5 and later, Watcom C++ 11.0 and later as well
27 # if defined(__VISUALC__) || defined(__BORLANDC__) || defined(__WATCOMC__)
28 # define WXEXPORT __declspec(dllexport)
29 # define WXIMPORT __declspec(dllimport)
31 While gcc also supports __declspec(dllexport), it creates unusably huge
32 DLL files since gcc 4.5 (while taking horribly long amounts of time),
33 see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43601. Because of this
34 we rely on binutils auto export/import support which seems to work
37 # elif defined(__GNUC__) && !wxCHECK_GCC_VERSION(4, 5)
39 __declspec could be used here too but let's use the native
40 __attribute__ instead for clarity.
42 # define WXEXPORT __attribute__((dllexport))
43 # define WXIMPORT __attribute__((dllimport))
45 #elif defined(__WXPM__)
46 # if defined (__WATCOMC__)
47 # define WXEXPORT __declspec(dllexport)
49 __declspec(dllimport) prepends __imp to imported symbols. We do NOT
53 # elif defined(__EMX__)
56 # elif (!(defined(__VISAGECPP__) && (__IBMCPP__ < 400 || __IBMC__ < 400 )))
57 # define WXEXPORT _Export
58 # define WXIMPORT _Export
60 #elif defined(__CYGWIN__)
61 # define WXEXPORT __declspec(dllexport)
62 # define WXIMPORT __declspec(dllimport)
65 /* for other platforms/compilers we don't anything */
72 We support building wxWidgets as a set of several libraries but we don't
73 support arbitrary combinations of libs/DLLs: either we build all of them as
74 DLLs (in which case WXMAKINGDLL is defined) or none (it isn't).
76 However we have a problem because we need separate WXDLLIMPEXP versions for
77 different libraries as, for example, wxString class should be dllexported
78 when compiled in wxBase and dllimported otherwise, so we do define separate
79 WXMAKING/USINGDLL_XYZ constants for each component XYZ.
83 # define WXMAKINGDLL_BASE
86 # define WXMAKINGDLL_NET
87 # define WXMAKINGDLL_CORE
88 # define WXMAKINGDLL_ADV
89 # define WXMAKINGDLL_QA
90 # define WXMAKINGDLL_HTML
91 # define WXMAKINGDLL_GL
92 # define WXMAKINGDLL_XML
93 # define WXMAKINGDLL_XRC
94 # define WXMAKINGDLL_AUI
95 # define WXMAKINGDLL_RIBBON
96 # define WXMAKINGDLL_PROPGRID
97 # define WXMAKINGDLL_RICHTEXT
98 # define WXMAKINGDLL_MEDIA
99 # define WXMAKINGDLL_STC
100 # define WXMAKINGDLL_WEBVIEW
101 #endif /* WXMAKINGDLL */
104 WXDLLIMPEXP_CORE maps to export declaration when building the DLL, to import
105 declaration if using it or to nothing at all if we don't use wxWin as DLL
107 #ifdef WXMAKINGDLL_BASE
108 # define WXDLLIMPEXP_BASE WXEXPORT
109 # define WXDLLIMPEXP_DATA_BASE(type) WXEXPORT type
110 # if defined(HAVE_VISIBILITY)
111 # define WXDLLIMPEXP_INLINE_BASE WXEXPORT
113 # define WXDLLIMPEXP_INLINE_BASE
115 #elif defined(WXUSINGDLL)
116 # define WXDLLIMPEXP_BASE WXIMPORT
117 # define WXDLLIMPEXP_DATA_BASE(type) WXIMPORT type
118 # if defined(HAVE_VISIBILITY)
119 # define WXDLLIMPEXP_INLINE_BASE WXIMPORT
121 # define WXDLLIMPEXP_INLINE_BASE
123 #else /* not making nor using DLL */
124 # define WXDLLIMPEXP_BASE
125 # define WXDLLIMPEXP_DATA_BASE(type) type
126 # define WXDLLIMPEXP_INLINE_BASE
129 #ifdef WXMAKINGDLL_NET
130 # define WXDLLIMPEXP_NET WXEXPORT
131 # define WXDLLIMPEXP_DATA_NET(type) WXEXPORT type
132 #elif defined(WXUSINGDLL)
133 # define WXDLLIMPEXP_NET WXIMPORT
134 # define WXDLLIMPEXP_DATA_NET(type) WXIMPORT type
135 #else /* not making nor using DLL */
136 # define WXDLLIMPEXP_NET
137 # define WXDLLIMPEXP_DATA_NET(type) type
140 #ifdef WXMAKINGDLL_CORE
141 # define WXDLLIMPEXP_CORE WXEXPORT
142 # define WXDLLIMPEXP_DATA_CORE(type) WXEXPORT type
143 # if defined(HAVE_VISIBILITY)
144 # define WXDLLIMPEXP_INLINE_CORE WXEXPORT
146 # define WXDLLIMPEXP_INLINE_CORE
148 #elif defined(WXUSINGDLL)
149 # define WXDLLIMPEXP_CORE WXIMPORT
150 # define WXDLLIMPEXP_DATA_CORE(type) WXIMPORT type
151 # if defined(HAVE_VISIBILITY)
152 # define WXDLLIMPEXP_INLINE_CORE WXIMPORT
154 # define WXDLLIMPEXP_INLINE_CORE
156 #else /* not making nor using DLL */
157 # define WXDLLIMPEXP_CORE
158 # define WXDLLIMPEXP_DATA_CORE(type) type
159 # define WXDLLIMPEXP_INLINE_CORE
162 #ifdef WXMAKINGDLL_ADV
163 # define WXDLLIMPEXP_ADV WXEXPORT
164 # define WXDLLIMPEXP_DATA_ADV(type) WXEXPORT type
165 #elif defined(WXUSINGDLL)
166 # define WXDLLIMPEXP_ADV WXIMPORT
167 # define WXDLLIMPEXP_DATA_ADV(type) WXIMPORT type
168 #else /* not making nor using DLL */
169 # define WXDLLIMPEXP_ADV
170 # define WXDLLIMPEXP_DATA_ADV(type) type
173 #ifdef WXMAKINGDLL_QA
174 # define WXDLLIMPEXP_QA WXEXPORT
175 # define WXDLLIMPEXP_DATA_QA(type) WXEXPORT type
176 #elif defined(WXUSINGDLL)
177 # define WXDLLIMPEXP_QA WXIMPORT
178 # define WXDLLIMPEXP_DATA_QA(type) WXIMPORT type
179 #else /* not making nor using DLL */
180 # define WXDLLIMPEXP_QA
181 # define WXDLLIMPEXP_DATA_QA(type) type
184 #ifdef WXMAKINGDLL_HTML
185 # define WXDLLIMPEXP_HTML WXEXPORT
186 # define WXDLLIMPEXP_DATA_HTML(type) WXEXPORT type
187 #elif defined(WXUSINGDLL)
188 # define WXDLLIMPEXP_HTML WXIMPORT
189 # define WXDLLIMPEXP_DATA_HTML(type) WXIMPORT type
190 #else /* not making nor using DLL */
191 # define WXDLLIMPEXP_HTML
192 # define WXDLLIMPEXP_DATA_HTML(type) type
195 #ifdef WXMAKINGDLL_GL
196 # define WXDLLIMPEXP_GL WXEXPORT
197 #elif defined(WXUSINGDLL)
198 # define WXDLLIMPEXP_GL WXIMPORT
199 #else /* not making nor using DLL */
200 # define WXDLLIMPEXP_GL
203 #ifdef WXMAKINGDLL_XML
204 # define WXDLLIMPEXP_XML WXEXPORT
205 #elif defined(WXUSINGDLL)
206 # define WXDLLIMPEXP_XML WXIMPORT
207 #else /* not making nor using DLL */
208 # define WXDLLIMPEXP_XML
211 #ifdef WXMAKINGDLL_XRC
212 # define WXDLLIMPEXP_XRC WXEXPORT
213 #elif defined(WXUSINGDLL)
214 # define WXDLLIMPEXP_XRC WXIMPORT
215 #else /* not making nor using DLL */
216 # define WXDLLIMPEXP_XRC
219 #ifdef WXMAKINGDLL_AUI
220 # define WXDLLIMPEXP_AUI WXEXPORT
221 #elif defined(WXUSINGDLL)
222 # define WXDLLIMPEXP_AUI WXIMPORT
223 #else /* not making nor using DLL */
224 # define WXDLLIMPEXP_AUI
227 #ifdef WXMAKINGDLL_RIBBON
228 # define WXDLLIMPEXP_RIBBON WXEXPORT
229 #elif defined(WXUSINGDLL)
230 # define WXDLLIMPEXP_RIBBON WXIMPORT
231 #else /* not making nor using DLL */
232 # define WXDLLIMPEXP_RIBBON
235 #ifdef WXMAKINGDLL_PROPGRID
236 # define WXDLLIMPEXP_PROPGRID WXEXPORT
237 # define WXDLLIMPEXP_DATA_PROPGRID(type) WXEXPORT type
238 #elif defined(WXUSINGDLL)
239 # define WXDLLIMPEXP_PROPGRID WXIMPORT
240 # define WXDLLIMPEXP_DATA_PROPGRID(type) WXIMPORT type
241 #else /* not making nor using DLL */
242 # define WXDLLIMPEXP_PROPGRID
243 # define WXDLLIMPEXP_DATA_PROPGRID(type) type
246 #ifdef WXMAKINGDLL_RICHTEXT
247 # define WXDLLIMPEXP_RICHTEXT WXEXPORT
248 #elif defined(WXUSINGDLL)
249 # define WXDLLIMPEXP_RICHTEXT WXIMPORT
250 #else /* not making nor using DLL */
251 # define WXDLLIMPEXP_RICHTEXT
254 #ifdef WXMAKINGDLL_MEDIA
255 # define WXDLLIMPEXP_MEDIA WXEXPORT
256 #elif defined(WXUSINGDLL)
257 # define WXDLLIMPEXP_MEDIA WXIMPORT
258 #else /* not making nor using DLL */
259 # define WXDLLIMPEXP_MEDIA
262 #ifdef WXMAKINGDLL_STC
263 # define WXDLLIMPEXP_STC WXEXPORT
264 # define WXDLLIMPEXP_DATA_STC(type) WXEXPORT type
265 #elif defined(WXUSINGDLL)
266 # define WXDLLIMPEXP_STC WXIMPORT
267 # define WXDLLIMPEXP_DATA_STC(type) WXIMPORT type
268 #else /* not making nor using DLL */
269 # define WXDLLIMPEXP_STC
270 # define WXDLLIMPEXP_DATA_STC(type) type
273 #ifdef WXMAKINGDLL_WEBVIEW
274 # define WXDLLIMPEXP_WEBVIEW WXEXPORT
275 # define WXDLLIMPEXP_DATA_WEBVIEW(type) WXEXPORT type
276 #elif defined(WXUSINGDLL)
277 # define WXDLLIMPEXP_WEBVIEW WXIMPORT
278 # define WXDLLIMPEXP_DATA_WEBVIEW(type) WXIMPORT type
279 #else /* not making nor using DLL */
280 # define WXDLLIMPEXP_WEBVIEW
281 # define WXDLLIMPEXP_DATA_WEBVIEW(type) type
285 GCC warns about using __attribute__ (and also __declspec in mingw32 case) on
286 forward declarations while MSVC complains about forward declarations without
287 __declspec for the classes later declared with it, so we need a separate set
288 of macros for forward declarations to hide this difference:
290 #if defined(HAVE_VISIBILITY) || (defined(__WINDOWS__) && defined(__GNUC__))
291 #define WXDLLIMPEXP_FWD_BASE
292 #define WXDLLIMPEXP_FWD_NET
293 #define WXDLLIMPEXP_FWD_CORE
294 #define WXDLLIMPEXP_FWD_ADV
295 #define WXDLLIMPEXP_FWD_QA
296 #define WXDLLIMPEXP_FWD_HTML
297 #define WXDLLIMPEXP_FWD_GL
298 #define WXDLLIMPEXP_FWD_XML
299 #define WXDLLIMPEXP_FWD_XRC
300 #define WXDLLIMPEXP_FWD_AUI
301 #define WXDLLIMPEXP_FWD_PROPGRID
302 #define WXDLLIMPEXP_FWD_RICHTEXT
303 #define WXDLLIMPEXP_FWD_MEDIA
304 #define WXDLLIMPEXP_FWD_STC
305 #define WXDLLIMPEXP_FWD_WEBVIEW
307 #define WXDLLIMPEXP_FWD_BASE WXDLLIMPEXP_BASE
308 #define WXDLLIMPEXP_FWD_NET WXDLLIMPEXP_NET
309 #define WXDLLIMPEXP_FWD_CORE WXDLLIMPEXP_CORE
310 #define WXDLLIMPEXP_FWD_ADV WXDLLIMPEXP_ADV
311 #define WXDLLIMPEXP_FWD_QA WXDLLIMPEXP_QA
312 #define WXDLLIMPEXP_FWD_HTML WXDLLIMPEXP_HTML
313 #define WXDLLIMPEXP_FWD_GL WXDLLIMPEXP_GL
314 #define WXDLLIMPEXP_FWD_XML WXDLLIMPEXP_XML
315 #define WXDLLIMPEXP_FWD_XRC WXDLLIMPEXP_XRC
316 #define WXDLLIMPEXP_FWD_AUI WXDLLIMPEXP_AUI
317 #define WXDLLIMPEXP_FWD_PROPGRID WXDLLIMPEXP_PROPGRID
318 #define WXDLLIMPEXP_FWD_RICHTEXT WXDLLIMPEXP_RICHTEXT
319 #define WXDLLIMPEXP_FWD_MEDIA WXDLLIMPEXP_MEDIA
320 #define WXDLLIMPEXP_FWD_STC WXDLLIMPEXP_STC
321 #define WXDLLIMPEXP_FWD_WEBVIEW WXDLLIMPEXP_WEBVIEW
324 /* for backwards compatibility, define suffix-less versions too */
325 #define WXDLLEXPORT WXDLLIMPEXP_CORE
326 #define WXDLLEXPORT_DATA WXDLLIMPEXP_DATA_CORE
329 MSVC up to 6.0 needs to be explicitly told to export template instantiations
330 used by the DLL clients, use this macro to do it like this:
332 template <typename T> class Foo { ... };
333 WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE( Foo<int> )
335 (notice that currently we only need this for wxBase and wxCore libraries)
337 #if defined(__VISUALC__) && (__VISUALC__ <= 1200)
338 #ifdef WXMAKINGDLL_BASE
339 #define WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE(decl) \
340 template class WXDLLIMPEXP_BASE decl;
341 #define WXDLLIMPEXP_TEMPLATE_INSTANCE_CORE(decl) \
342 template class WXDLLIMPEXP_CORE decl;
345 We need to disable this warning when using this macro, as
346 recommended by Microsoft itself:
348 http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b168958
350 #pragma warning(disable:4231)
352 #define WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE(decl) \
353 extern template class WXDLLIMPEXP_BASE decl;
354 #define WXDLLIMPEXP_TEMPLATE_INSTANCE_CORE(decl) \
355 extern template class WXDLLIMPEXP_CORE decl;
357 #else /* not VC <= 6 */
358 #define WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE(decl)
359 #define WXDLLIMPEXP_TEMPLATE_INSTANCE_CORE(decl)
360 #endif /* VC6/others */
362 #endif /* _WX_DLIMPEXP_H_ */