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_NOEXTERN
38 #undef WS_DLL_PUBLIC_NOEXTERN
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 library; 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 __attribute__ ((dllexport)) extern
64 #define WS_DLL_PUBLIC_NOEXTERN __attribute__ ((dllexport))
65 #else /* ! __GNUC__ */
68 * Note: actually gcc seems to also support this syntax.
70 #define WS_DLL_PUBLIC __declspec(dllexport) extern
71 #define WS_DLL_PUBLIC_NOEXTERN __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 __attribute__ ((dllimport)) extern
86 #define WS_DLL_PUBLIC_NOEXTERN __attribute__ ((dllimport))
87 #elif ! (defined ENABLE_STATIC) /* ! __GNUC__ */
90 * Note: actually gcc seems to also support this syntax.
92 #define WS_DLL_PUBLIC __declspec(dllimport) extern
93 #define WS_DLL_PUBLIC_NOEXTERN __declspec(dllimport)
94 #else /* ! __GNUC__ && ENABLE_STATIC */
96 #define WS_DLL_PUBLIC extern
97 #define WS_DLL_PUBLIC_NOEXTERN
99 #endif /* WS_BUILD_DLL */
101 #else /* defined _WIN32 || defined __CYGWIN__ */
103 * Compiling for UN*X, where the dllimport and dllexport stuff
104 * is neither necessary nor supported; just specify the
105 * visibility if we have a compiler that claims compatibility
106 * with GCC 4 or later.
109 #define WS_DLL_PUBLIC __attribute__ ((visibility ("default"))) extern
110 #define WS_DLL_PUBLIC_NOEXTERN __attribute__ ((visibility ("default")))
111 #define WS_DLL_LOCAL __attribute__ ((visibility ("hidden")))
112 #else /* ! __GNUC__ >= 4 */
113 #define WS_DLL_PUBLIC extern
114 #define WS_DLL_PUBLIC_NOEXTERN
116 #endif /* __GNUC__ >= 4 */
119 #endif /* SYMBOL_EXPORT_H */