2 * Cross platform defines for exporting symbols from shared libraries
6 * Wireshark - Network traffic analyzer
7 * By Balint Reczey <balint@balintreczey.hu>
8 * Copyright 2013 Balint Reczey
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 /** Reset symbol export behavior.
26 * If you {un}define WS_BUILD_DLL on the fly you'll have to define this
29 #ifdef RESET_SYMBOL_EXPORT
31 #ifdef SYMBOL_EXPORT_H
32 #undef SYMBOL_EXPORT_H
39 #ifdef WS_DLL_PUBLIC_DEF
40 #undef WS_DLL_PUBLIC_DEF
47 #endif /* RESET_SYMBOL_EXPORT */
49 #ifndef SYMBOL_EXPORT_H
50 #define SYMBOL_EXPORT_H
52 /* Originally copied from GCC Wiki at http://gcc.gnu.org/wiki/Visibility */
53 #if defined _WIN32 || defined __CYGWIN__
54 /* Compiling for Windows, so we use the Windows DLL declarations. */
57 * Building a DLL; for all definitions, we want dllexport, and
58 * (presumably so source from DLL and source from a program using the
59 * DLL can both include a header that declares APIs and exported data
60 * for the DLL), for declarations, either dllexport or dllimport will
61 * work (they mean the same thing for a declaration when building a DLL).
65 #define WS_DLL_PUBLIC_DEF __attribute__ ((dllexport))
66 #else /* ! __GNUC__ */
69 * Note: actually gcc seems to also support this syntax.
71 #define WS_DLL_PUBLIC_DEF __declspec(dllexport)
73 #else /* WS_BUILD_DLL */
75 * Building a program; we should only see declarations, not definitions,
76 * with WS_DLL_PUBLIC, and they all represent APIs or data imported
77 * from a DLL, so use dllimport.
79 * For functions, export shouldn't be necessary; for data, it might
80 * be necessary, e.g. if what's declared is an array whose size is
81 * not given in the declaration.
85 #define WS_DLL_PUBLIC_DEF __attribute__ ((dllimport))
86 #elif ! (defined ENABLE_STATIC) /* ! __GNUC__ */
88 * Presumably MSVC, and we're not building all-static.
89 * Note: actually gcc seems to also support this syntax.
91 #define WS_DLL_PUBLIC_DEF __declspec(dllimport)
92 #else /* ! __GNUC__ && ENABLE_STATIC */
94 * Presumably MSVC, and we're building all-static, so we're
95 * not building any DLLs.
97 #define WS_DLL_PUBLIC_DEF
99 #endif /* WS_BUILD_DLL */
102 * Symbols in a DLL are *not* exported unless they're specifically
103 * flagged as exported, so, for a non-static but non-exported
104 * symbol, we don't have to do anything.
107 #else /* defined _WIN32 || defined __CYGWIN__ */
109 * Compiling for UN*X, where the dllimport and dllexport stuff
110 * is neither necessary nor supported; just specify the
111 * visibility if we have a compiler that claims compatibility
112 * with GCC 4 or later.
116 * Symbols exported from libraries.
118 #define WS_DLL_PUBLIC_DEF __attribute__ ((visibility ("default")))
121 * Non-static symbols *not* exported from libraries.
123 #define WS_DLL_LOCAL __attribute__ ((visibility ("hidden")))
124 #else /* ! __GNUC__ >= 4 */
126 * We have no way to control visibility.
128 #define WS_DLL_PUBLIC_DEF
130 #endif /* __GNUC__ >= 4 */
134 * You *must* use this for exported data *declarations*; if you use
135 * WS_DLL_PUBLIC_DEF, some compilers, such as MSVC++, will complain
136 * about array definitions with no size.
138 * You must *not* use this for exported data *definitions*, as that
139 * will, for some compilers, cause warnings about items being initialized
140 * and declared extern.
142 * Either can be used for exported *function* declarations and definitions.
144 #define WS_DLL_PUBLIC WS_DLL_PUBLIC_DEF extern
146 #endif /* SYMBOL_EXPORT_H */