]>
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(__WXMAC__) || defined(__WXCOCOA__)
62 # define WXEXPORT __declspec(export)
63 # define WXIMPORT __declspec(import)
65 #elif defined(__CYGWIN__)
66 # define WXEXPORT __declspec(dllexport)
67 # define WXIMPORT __declspec(dllimport)
70 /* for other platforms/compilers we don't anything */
77 We support building wxWidgets as a set of several libraries but we don't
78 support arbitrary combinations of libs/DLLs: either we build all of them as
79 DLLs (in which case WXMAKINGDLL is defined) or none (it isn't).
81 However we have a problem because we need separate WXDLLIMPEXP versions for
82 different libraries as, for example, wxString class should be dllexported
83 when compiled in wxBase and dllimported otherwise, so we do define separate
84 WXMAKING/USINGDLL_XYZ constants for each component XYZ.
88 # define WXMAKINGDLL_BASE
91 # define WXMAKINGDLL_NET
92 # define WXMAKINGDLL_CORE
93 # define WXMAKINGDLL_ADV
94 # define WXMAKINGDLL_QA
95 # define WXMAKINGDLL_HTML
96 # define WXMAKINGDLL_GL
97 # define WXMAKINGDLL_XML
98 # define WXMAKINGDLL_XRC
99 # define WXMAKINGDLL_AUI
100 # define WXMAKINGDLL_RIBBON
101 # define WXMAKINGDLL_PROPGRID
102 # define WXMAKINGDLL_RICHTEXT
103 # define WXMAKINGDLL_MEDIA
104 # define WXMAKINGDLL_STC
105 #endif /* WXMAKINGDLL */
108 WXDLLIMPEXP_CORE maps to export declaration when building the DLL, to import
109 declaration if using it or to nothing at all if we don't use wxWin as DLL
111 #ifdef WXMAKINGDLL_BASE
112 # define WXDLLIMPEXP_BASE WXEXPORT
113 # define WXDLLIMPEXP_DATA_BASE(type) WXEXPORT type
114 # if defined(HAVE_VISIBILITY)
115 # define WXDLLIMPEXP_INLINE_BASE WXEXPORT
117 # define WXDLLIMPEXP_INLINE_BASE
119 #elif defined(WXUSINGDLL)
120 # define WXDLLIMPEXP_BASE WXIMPORT
121 # define WXDLLIMPEXP_DATA_BASE(type) WXIMPORT type
122 # if defined(HAVE_VISIBILITY)
123 # define WXDLLIMPEXP_INLINE_BASE WXIMPORT
125 # define WXDLLIMPEXP_INLINE_BASE
127 #else /* not making nor using DLL */
128 # define WXDLLIMPEXP_BASE
129 # define WXDLLIMPEXP_DATA_BASE(type) type
130 # define WXDLLIMPEXP_INLINE_BASE
133 #ifdef WXMAKINGDLL_NET
134 # define WXDLLIMPEXP_NET WXEXPORT
135 # define WXDLLIMPEXP_DATA_NET(type) WXEXPORT type
136 #elif defined(WXUSINGDLL)
137 # define WXDLLIMPEXP_NET WXIMPORT
138 # define WXDLLIMPEXP_DATA_NET(type) WXIMPORT type
139 #else /* not making nor using DLL */
140 # define WXDLLIMPEXP_NET
141 # define WXDLLIMPEXP_DATA_NET(type) type
144 #ifdef WXMAKINGDLL_CORE
145 # define WXDLLIMPEXP_CORE WXEXPORT
146 # define WXDLLIMPEXP_DATA_CORE(type) WXEXPORT type
147 # if defined(HAVE_VISIBILITY)
148 # define WXDLLIMPEXP_INLINE_CORE WXEXPORT
150 # define WXDLLIMPEXP_INLINE_CORE
152 #elif defined(WXUSINGDLL)
153 # define WXDLLIMPEXP_CORE WXIMPORT
154 # define WXDLLIMPEXP_DATA_CORE(type) WXIMPORT type
155 # if defined(HAVE_VISIBILITY)
156 # define WXDLLIMPEXP_INLINE_CORE WXIMPORT
158 # define WXDLLIMPEXP_INLINE_CORE
160 #else /* not making nor using DLL */
161 # define WXDLLIMPEXP_CORE
162 # define WXDLLIMPEXP_DATA_CORE(type) type
163 # define WXDLLIMPEXP_INLINE_CORE
166 #ifdef WXMAKINGDLL_ADV
167 # define WXDLLIMPEXP_ADV WXEXPORT
168 # define WXDLLIMPEXP_DATA_ADV(type) WXEXPORT type
169 #elif defined(WXUSINGDLL)
170 # define WXDLLIMPEXP_ADV WXIMPORT
171 # define WXDLLIMPEXP_DATA_ADV(type) WXIMPORT type
172 #else /* not making nor using DLL */
173 # define WXDLLIMPEXP_ADV
174 # define WXDLLIMPEXP_DATA_ADV(type) type
177 #ifdef WXMAKINGDLL_QA
178 # define WXDLLIMPEXP_QA WXEXPORT
179 # define WXDLLIMPEXP_DATA_QA(type) WXEXPORT type
180 #elif defined(WXUSINGDLL)
181 # define WXDLLIMPEXP_QA WXIMPORT
182 # define WXDLLIMPEXP_DATA_QA(type) WXIMPORT type
183 #else /* not making nor using DLL */
184 # define WXDLLIMPEXP_QA
185 # define WXDLLIMPEXP_DATA_QA(type) type
188 #ifdef WXMAKINGDLL_HTML
189 # define WXDLLIMPEXP_HTML WXEXPORT
190 # define WXDLLIMPEXP_DATA_HTML(type) WXEXPORT type
191 #elif defined(WXUSINGDLL)
192 # define WXDLLIMPEXP_HTML WXIMPORT
193 # define WXDLLIMPEXP_DATA_HTML(type) WXIMPORT type
194 #else /* not making nor using DLL */
195 # define WXDLLIMPEXP_HTML
196 # define WXDLLIMPEXP_DATA_HTML(type) type
199 #ifdef WXMAKINGDLL_GL
200 # define WXDLLIMPEXP_GL WXEXPORT
201 #elif defined(WXUSINGDLL)
202 # define WXDLLIMPEXP_GL WXIMPORT
203 #else /* not making nor using DLL */
204 # define WXDLLIMPEXP_GL
207 #ifdef WXMAKINGDLL_XML
208 # define WXDLLIMPEXP_XML WXEXPORT
209 #elif defined(WXUSINGDLL)
210 # define WXDLLIMPEXP_XML WXIMPORT
211 #else /* not making nor using DLL */
212 # define WXDLLIMPEXP_XML
215 #ifdef WXMAKINGDLL_XRC
216 # define WXDLLIMPEXP_XRC WXEXPORT
217 #elif defined(WXUSINGDLL)
218 # define WXDLLIMPEXP_XRC WXIMPORT
219 #else /* not making nor using DLL */
220 # define WXDLLIMPEXP_XRC
223 #ifdef WXMAKINGDLL_AUI
224 # define WXDLLIMPEXP_AUI WXEXPORT
225 #elif defined(WXUSINGDLL)
226 # define WXDLLIMPEXP_AUI WXIMPORT
227 #else /* not making nor using DLL */
228 # define WXDLLIMPEXP_AUI
231 #ifdef WXMAKINGDLL_RIBBON
232 # define WXDLLIMPEXP_RIBBON WXEXPORT
233 #elif defined(WXUSINGDLL)
234 # define WXDLLIMPEXP_RIBBON WXIMPORT
235 #else /* not making nor using DLL */
236 # define WXDLLIMPEXP_RIBBON
239 #ifdef WXMAKINGDLL_PROPGRID
240 # define WXDLLIMPEXP_PROPGRID WXEXPORT
241 # define WXDLLIMPEXP_DATA_PROPGRID(type) WXEXPORT type
242 #elif defined(WXUSINGDLL)
243 # define WXDLLIMPEXP_PROPGRID WXIMPORT
244 # define WXDLLIMPEXP_DATA_PROPGRID(type) WXIMPORT type
245 #else /* not making nor using DLL */
246 # define WXDLLIMPEXP_PROPGRID
247 # define WXDLLIMPEXP_DATA_PROPGRID(type) type
250 #ifdef WXMAKINGDLL_RICHTEXT
251 # define WXDLLIMPEXP_RICHTEXT WXEXPORT
252 #elif defined(WXUSINGDLL)
253 # define WXDLLIMPEXP_RICHTEXT WXIMPORT
254 #else /* not making nor using DLL */
255 # define WXDLLIMPEXP_RICHTEXT
258 #ifdef WXMAKINGDLL_MEDIA
259 # define WXDLLIMPEXP_MEDIA WXEXPORT
260 #elif defined(WXUSINGDLL)
261 # define WXDLLIMPEXP_MEDIA WXIMPORT
262 #else /* not making nor using DLL */
263 # define WXDLLIMPEXP_MEDIA
266 #ifdef WXMAKINGDLL_STC
267 # define WXDLLIMPEXP_STC WXEXPORT
268 # define WXDLLIMPEXP_DATA_STC(type) WXEXPORT type
269 #elif defined(WXUSINGDLL)
270 # define WXDLLIMPEXP_STC WXIMPORT
271 # define WXDLLIMPEXP_DATA_STC(type) WXIMPORT type
272 #else /* not making nor using DLL */
273 # define WXDLLIMPEXP_STC
274 # define WXDLLIMPEXP_DATA_STC(type) type
278 GCC warns about using __attribute__ (and also __declspec in mingw32 case) on
279 forward declarations while MSVC complains about forward declarations without
280 __declspec for the classes later declared with it, so we need a separate set
281 of macros for forward declarations to hide this difference:
283 #if defined(HAVE_VISIBILITY) || (defined(__WINDOWS__) && defined(__GNUC__))
284 #define WXDLLIMPEXP_FWD_BASE
285 #define WXDLLIMPEXP_FWD_NET
286 #define WXDLLIMPEXP_FWD_CORE
287 #define WXDLLIMPEXP_FWD_ADV
288 #define WXDLLIMPEXP_FWD_QA
289 #define WXDLLIMPEXP_FWD_HTML
290 #define WXDLLIMPEXP_FWD_GL
291 #define WXDLLIMPEXP_FWD_XML
292 #define WXDLLIMPEXP_FWD_XRC
293 #define WXDLLIMPEXP_FWD_AUI
294 #define WXDLLIMPEXP_FWD_PROPGRID
295 #define WXDLLIMPEXP_FWD_RICHTEXT
296 #define WXDLLIMPEXP_FWD_MEDIA
297 #define WXDLLIMPEXP_FWD_STC
299 #define WXDLLIMPEXP_FWD_BASE WXDLLIMPEXP_BASE
300 #define WXDLLIMPEXP_FWD_NET WXDLLIMPEXP_NET
301 #define WXDLLIMPEXP_FWD_CORE WXDLLIMPEXP_CORE
302 #define WXDLLIMPEXP_FWD_ADV WXDLLIMPEXP_ADV
303 #define WXDLLIMPEXP_FWD_QA WXDLLIMPEXP_QA
304 #define WXDLLIMPEXP_FWD_HTML WXDLLIMPEXP_HTML
305 #define WXDLLIMPEXP_FWD_GL WXDLLIMPEXP_GL
306 #define WXDLLIMPEXP_FWD_XML WXDLLIMPEXP_XML
307 #define WXDLLIMPEXP_FWD_XRC WXDLLIMPEXP_XRC
308 #define WXDLLIMPEXP_FWD_AUI WXDLLIMPEXP_AUI
309 #define WXDLLIMPEXP_FWD_PROPGRID WXDLLIMPEXP_PROPGRID
310 #define WXDLLIMPEXP_FWD_RICHTEXT WXDLLIMPEXP_RICHTEXT
311 #define WXDLLIMPEXP_FWD_MEDIA WXDLLIMPEXP_MEDIA
312 #define WXDLLIMPEXP_FWD_STC WXDLLIMPEXP_STC
315 /* for backwards compatibility, define suffix-less versions too */
316 #define WXDLLEXPORT WXDLLIMPEXP_CORE
317 #define WXDLLEXPORT_DATA WXDLLIMPEXP_DATA_CORE
320 MSVC up to 6.0 needs to be explicitly told to export template instantiations
321 used by the DLL clients, use this macro to do it like this:
323 template <typename T> class Foo { ... };
324 WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE( Foo<int> )
326 (notice that currently we only need this for wxBase and wxCore libraries)
328 #if defined(__VISUALC__) && (__VISUALC__ <= 1200)
329 #ifdef WXMAKINGDLL_BASE
330 #define WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE(decl) \
331 template class WXDLLIMPEXP_BASE decl;
332 #define WXDLLIMPEXP_TEMPLATE_INSTANCE_CORE(decl) \
333 template class WXDLLIMPEXP_CORE decl;
336 We need to disable this warning when using this macro, as
337 recommended by Microsoft itself:
339 http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b168958
341 #pragma warning(disable:4231)
343 #define WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE(decl) \
344 extern template class WXDLLIMPEXP_BASE decl;
345 #define WXDLLIMPEXP_TEMPLATE_INSTANCE_CORE(decl) \
346 extern template class WXDLLIMPEXP_CORE decl;
348 #else /* not VC <= 6 */
349 #define WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE(decl)
350 #define WXDLLIMPEXP_TEMPLATE_INSTANCE_CORE(decl)
351 #endif /* VC6/others */
353 #endif /* _WX_DLIMPEXP_H_ */