2 * Cross platform defines for exporting symbols from shared libraries
4 * Wireshark - Network traffic analyzer
5 * By Balint Reczey <balint@balintreczey.hu>
6 * Copyright 2013 Balint Reczey
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 /** Reset symbol export behavior.
24 * If you {un}define WS_BUILD_DLL on the fly you'll have to define this
27 #ifdef RESET_SYMBOL_EXPORT
29 #ifdef SYMBOL_EXPORT_H
30 #undef SYMBOL_EXPORT_H
37 #ifdef WS_DLL_PUBLIC_DEF
38 #undef WS_DLL_PUBLIC_DEF
45 #endif /* RESET_SYMBOL_EXPORT */
47 #ifndef SYMBOL_EXPORT_H
48 #define SYMBOL_EXPORT_H
51 * NOTE: G_HAVE_GNUC_VISIBILITY is defined only if all of
53 * __attribute__ ((visibility ("hidden")))
55 * __attribute__ ((visibility ("internal")))
57 * __attribute__ ((visibility ("protected")))
59 * __attribute__ ((visibility ("default")))
61 * are supported, and at least some versions of GCC from Apple support
62 * "default" and "hidden" but not "internal" or "protected", so it
63 * shouldn't be used to determine whether "hidden" or "default" is
66 * This also means that we shouldn't use G_GNUC_INTERNAL instead of
67 * WS_DLL_LOCAL, as GLib uses G_HAVE_GNUC_VISIBILITY to determine
68 * whether to use __attribute__ ((visibility ("hidden"))) for
69 * G_GNUC_INTERNAL, and that will not use it even with compilers
73 /* Originally copied from GCC Wiki at http://gcc.gnu.org/wiki/Visibility */
74 #if defined _WIN32 || defined __CYGWIN__
75 /* Compiling for Windows, so we use the Windows DLL declarations. */
78 * Building a DLL; for all definitions, we want dllexport, and
79 * (presumably so source from DLL and source from a program using the
80 * DLL can both include a header that declares APIs and exported data
81 * for the DLL), for declarations, either dllexport or dllimport will
82 * work (they mean the same thing for a declaration when building a DLL).
86 #define WS_DLL_PUBLIC_DEF __attribute__ ((dllexport))
87 #else /* ! __GNUC__ */
90 * Note: actually gcc seems to also support this syntax.
92 #define WS_DLL_PUBLIC_DEF __declspec(dllexport)
94 #else /* WS_BUILD_DLL */
96 * Building a program; we should only see declarations, not definitions,
97 * with WS_DLL_PUBLIC, and they all represent APIs or data imported
98 * from a DLL, so use dllimport.
100 * For functions, export shouldn't be necessary; for data, it might
101 * be necessary, e.g. if what's declared is an array whose size is
102 * not given in the declaration.
106 #define WS_DLL_PUBLIC_DEF __attribute__ ((dllimport))
107 #elif ! (defined ENABLE_STATIC) /* ! __GNUC__ */
109 * Presumably MSVC, and we're not building all-static.
110 * Note: actually gcc seems to also support this syntax.
112 #define WS_DLL_PUBLIC_DEF __declspec(dllimport)
113 #else /* ! __GNUC__ && ENABLE_STATIC */
115 * Presumably MSVC, and we're building all-static, so we're
116 * not building any DLLs.
118 #define WS_DLL_PUBLIC_DEF
119 #endif /* __GNUC__ */
120 #endif /* WS_BUILD_DLL */
123 * Symbols in a DLL are *not* exported unless they're specifically
124 * flagged as exported, so, for a non-static but non-exported
125 * symbol, we don't have to do anything.
128 #else /* defined _WIN32 || defined __CYGWIN__ */
130 * Compiling for UN*X, where the dllimport and dllexport stuff
131 * is neither necessary nor supported; just specify the
132 * visibility if we have a compiler that claims compatibility
133 * with GCC 4 or later.
137 * Symbols exported from libraries.
139 #define WS_DLL_PUBLIC_DEF __attribute__ ((visibility ("default")))
142 * Non-static symbols *not* exported from libraries.
144 #define WS_DLL_LOCAL __attribute__ ((visibility ("hidden")))
145 #else /* ! __GNUC__ >= 4 */
147 * We have no way to make stuff not explicitly marked as
148 * visible invisible outside a library, but we might have
149 * a way to make stuff explicitly marked as local invisible
150 * outside the library.
152 * This was lifted from GLib; see above for why we don't use
155 #if defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
156 /* This supports GCC-style __attribute__ ((visibility (XXX))) */
157 #define WS_DLL_PUBLIC_DEF __attribute__ ((visibility ("default")))
158 #define WS_DLL_LOCAL __attribute__ ((visibility ("hidden")))
159 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
160 /* This doesn't, but supports __global and __hidden */
161 #define WS_DLL_PUBLIC_DEF __global
162 #define WS_DLL_LOCAL __hidden
163 #else /* not Sun C with "hidden" support */
164 #define WS_DLL_PUBLIC_DEF
167 #endif /* __GNUC__ >= 4 */
171 * You *must* use this for exported data *declarations*; if you use
172 * WS_DLL_PUBLIC_DEF, some compilers, such as MSVC++, will complain
173 * about array definitions with no size.
175 * You must *not* use this for exported data *definitions*, as that
176 * will, for some compilers, cause warnings about items being initialized
177 * and declared extern.
179 * Either can be used for exported *function* declarations and definitions.
181 #define WS_DLL_PUBLIC WS_DLL_PUBLIC_DEF extern
183 #endif /* SYMBOL_EXPORT_H */
186 * Editor modelines - http://www.wireshark.org/tools/modelines.html
191 * indent-tabs-mode: nil
194 * vi: set shiftwidth=2 tabstop=8 expandtab:
195 * :indentSize=2:tabSize=8:noTabs=true: