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
50 /* Originally copied from GCC Wiki at http://gcc.gnu.org/wiki/Visibility */
51 #if defined _WIN32 || defined __CYGWIN__
52 /* Compiling for Windows, so we use the Windows DLL declarations. */
55 * Building a DLL; for all definitions, we want dllexport, and
56 * (presumably so source from DLL and source from a program using the
57 * DLL can both include a header that declares APIs and exported data
58 * for the DLL), for declarations, either dllexport or dllimport will
59 * work (they mean the same thing for a declaration when building a DLL).
63 #define WS_DLL_PUBLIC_DEF __attribute__ ((dllexport))
64 #else /* ! __GNUC__ */
67 * Note: actually gcc seems to also support this syntax.
69 #define WS_DLL_PUBLIC_DEF __declspec(dllexport)
71 #else /* WS_BUILD_DLL */
73 * Building a program; we should only see declarations, not definitions,
74 * with WS_DLL_PUBLIC, and they all represent APIs or data imported
75 * from a DLL, so use dllimport.
77 * For functions, export shouldn't be necessary; for data, it might
78 * be necessary, e.g. if what's declared is an array whose size is
79 * not given in the declaration.
83 #define WS_DLL_PUBLIC_DEF __attribute__ ((dllimport))
84 #elif ! (defined ENABLE_STATIC) /* ! __GNUC__ */
86 * Presumably MSVC, and we're not building all-static.
87 * Note: actually gcc seems to also support this syntax.
89 #define WS_DLL_PUBLIC_DEF __declspec(dllimport)
90 #else /* ! __GNUC__ && ENABLE_STATIC */
92 * Presumably MSVC, and we're building all-static, so we're
93 * not building any DLLs.
95 #define WS_DLL_PUBLIC_DEF
97 #endif /* WS_BUILD_DLL */
100 * Symbols in a DLL are *not* exported unless they're specifically
101 * flagged as exported, so, for a non-static but non-exported
102 * symbol, we don't have to do anything.
105 #else /* defined _WIN32 || defined __CYGWIN__ */
107 * Compiling for UN*X, where the dllimport and dllexport stuff
108 * is neither necessary nor supported; just specify the
109 * visibility if we have a compiler that claims compatibility
110 * with GCC 4 or later.
114 * Symbols exported from libraries.
116 #define WS_DLL_PUBLIC_DEF __attribute__ ((visibility ("default")))
119 * Non-static symbols *not* exported from libraries.
121 #define WS_DLL_LOCAL __attribute__ ((visibility ("hidden")))
122 #else /* ! __GNUC__ >= 4 */
124 * We have no way to control visibility.
126 #define WS_DLL_PUBLIC_DEF
128 #endif /* __GNUC__ >= 4 */
132 * Use this for declarations; it can also be used for exported
133 * *function* definitions, but must not be used for exported *data*
136 #define WS_DLL_PUBLIC WS_DLL_PUBLIC_DEF extern
138 #endif /* SYMBOL_EXPORT_H */