3 * Copyright 1998-2002 The OpenLDAP Foundation, Redwood City, California, USA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted only as authorized by the OpenLDAP
8 * Public License. A copy of this license is available at
9 * http://www.OpenLDAP.org/license.html or in file LICENSE in the
10 * top-level directory of the distribution.
17 #if defined(__cplusplus) || defined(c_plusplus)
18 # define LDAP_BEGIN_DECL extern "C" {
19 # define LDAP_END_DECL }
21 # define LDAP_BEGIN_DECL /* begin declarations */
22 # define LDAP_END_DECL /* end declarations */
25 #if !defined(LDAP_NO_PROTOTYPES) && ( defined(LDAP_NEEDS_PROTOTYPES) || \
26 defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) )
29 # define LDAP_P(protos) protos
30 # define LDAP_CONCAT1(x,y) x ## y
31 # define LDAP_CONCAT(x,y) LDAP_CONCAT1(x,y)
32 # define LDAP_STRING(x) #x /* stringify without expanding x */
33 # define LDAP_XSTRING(x) LDAP_STRING(x) /* expand x, then stringify */
36 # define LDAP_CONST const
39 #else /* no prototypes */
42 # define LDAP_P(protos) ()
43 # define LDAP_CONCAT(x,y) x/**/y
44 # define LDAP_STRING(x) "x"
47 # define LDAP_CONST /* no const */
50 #endif /* no prototypes */
52 #if (__GNUC__) * 1000 + (__GNUC_MINOR__) >= 2006
53 # define LDAP_GCCATTR(attrs) __attribute__(attrs)
55 # define LDAP_GCCATTR(attrs)
59 * Support for Windows DLLs.
61 * When external source code includes header files for dynamic libraries,
62 * the external source code is "importing" DLL symbols into its resulting
63 * object code. On Windows, symbols imported from DLLs must be explicitly
64 * indicated in header files with the __declspec(dllimport) directive.
65 * This is not totally necessary for functions because the compiler
66 * (gcc or MSVC) will generate stubs when this directive is absent.
67 * However, this is required for imported variables.
69 * The LDAP libraries, i.e. liblber and libldap, can be built as
70 * static or shared, based on configuration. Just about all other source
71 * code in OpenLDAP use these libraries. If the LDAP libraries
72 * are configured as shared, 'configure' defines the LDAP_LIBS_DYNAMIC
73 * macro. When other source files include LDAP library headers, the
74 * LDAP library symbols will automatically be marked as imported. When
75 * the actual LDAP libraries are being built, the symbols will not
76 * be marked as imported because the LBER_LIBRARY or LDAP_LIBRARY macros
77 * will be respectively defined.
79 * Any project outside of OpenLDAP with source code wanting to use
80 * LDAP dynamic libraries should explicitly define LDAP_LIBS_DYNAMIC.
81 * This will ensure that external source code appropriately marks symbols
82 * that will be imported.
84 * The slapd executable, itself, can be used as a dynamic library.
85 * For example, if a backend module is compiled as shared, it will
86 * import symbols from slapd. When this happens, the slapd symbols
87 * must be marked as imported in header files that the backend module
88 * includes. Remember that slapd links with various static libraries.
89 * If the LDAP libraries were configured as static, their object
90 * code is also part of the monolithic slapd executable. Thus, when
91 * a backend module imports symbols from slapd, it imports symbols from
92 * all of the static libraries in slapd as well. Thus, the SLAP_IMPORT
93 * macro, when defined, will appropriately mark symbols as imported.
94 * This macro should be used by shared backend modules as well as any
95 * other external source code that imports symbols from the slapd
96 * executable as if it were a DLL.
98 * Note that we don't actually have to worry about using the
99 * __declspec(dllexport) directive anywhere. This is because both
100 * MSVC and Mingw provide alternate (more effective) methods for exporting
101 * symbols out of binaries, i.e. the use of a DEF file.
103 * NOTE ABOUT BACKENDS: Backends can be configured as static or dynamic.
104 * When a backend is configured as dynamic, slapd will load the backend
105 * explicitly and populate function pointer structures by calling
106 * the backend's well-known initialization function. Because of this
107 * procedure, slapd never implicitly imports symbols from dynamic backends.
108 * This makes it unnecessary to tag various backend functions with the
109 * __declspec(dllimport) directive. This is because neither slapd nor
110 * any other external binary should ever be implicitly loading a backend
113 * Backends are supposed to be self-contained. However, it appears that
114 * back-meta DOES implicitly import symbols from back-ldap. This means
115 * that the __declspec(dllimport) directive should be marked on back-ldap
116 * functions (in its header files) if and only if we're compiling for
117 * windows AND back-ldap has been configured as dynamic AND back-meta
118 * is the client of back-ldap. When client is slapd, there is no effect
119 * since slapd does not implicitly import symbols.
121 * TODO(?): Currently, back-meta nor back-ldap is supported for Mingw32.
122 * Thus, there's no need to worry about this right now. This is something that
123 * may or may not have to be addressed in the future.
127 #if defined(_WIN32) && \
128 ((defined(LDAP_LIBS_DYNAMIC) && !defined(LBER_LIBRARY)) || \
129 (!defined(LDAP_LIBS_DYNAMIC) && defined(SLAPD_IMPORT)))
130 # define LBER_F(type) extern __declspec(dllimport) type
131 # define LBER_V(type) extern __declspec(dllimport) type
133 # define LBER_F(type) extern type
134 # define LBER_V(type) extern type
138 #if defined(_WIN32) && \
139 ((defined(LDAP_LIBS_DYNAMIC) && !defined(LDAP_LIBRARY)) || \
140 (!defined(LDAP_LIBS_DYNAMIC) && defined(SLAPD_IMPORT)))
141 # define LDAP_F(type) extern __declspec(dllimport) type
142 # define LDAP_V(type) extern __declspec(dllimport) type
144 # define LDAP_F(type) extern type
145 # define LDAP_V(type) extern type
149 #if defined(_WIN32) && defined(SLAPD_IMPORT)
150 # define LDAP_AVL_F(type) extern __declspec(dllimport) type
151 # define LDAP_AVL_V(type) extern __declspec(dllimport) type
153 # define LDAP_AVL_F(type) extern type
154 # define LDAP_AVL_V(type) extern type
158 #if defined(_WIN32) && defined(SLAPD_IMPORT)
159 # define LDAP_LDBM_F(type) extern __declspec(dllimport) type
160 # define LDAP_LDBM_V(type) extern __declspec(dllimport) type
162 # define LDAP_LDBM_F(type) extern type
163 # define LDAP_LDBM_V(type) extern type
167 #if defined(_WIN32) && defined(SLAPD_IMPORT)
168 # define LDAP_LDIF_F(type) extern __declspec(dllimport) type
169 # define LDAP_LDIF_V(type) extern __declspec(dllimport) type
171 # define LDAP_LDIF_F(type) extern type
172 # define LDAP_LDIF_V(type) extern type
175 /* LUNICODE library */
176 #if defined(_WIN32) && defined(SLAPD_IMPORT)
177 # define LDAP_LUNICODE_F(type) extern __declspec(dllimport) type
178 # define LDAP_LUNICODE_V(type) extern __declspec(dllimport) type
180 # define LDAP_LUNICODE_F(type) extern type
181 # define LDAP_LUNICODE_V(type) extern type
185 #if defined(_WIN32) && defined(SLAPD_IMPORT)
186 # define LDAP_LUTIL_F(type) extern __declspec(dllimport) type
187 # define LDAP_LUTIL_V(type) extern __declspec(dllimport) type
189 # define LDAP_LUTIL_F(type) extern type
190 # define LDAP_LUTIL_V(type) extern type
193 /* REWRITE library */
194 #if defined(_WIN32) && defined(SLAPD_IMPORT)
195 # define LDAP_REWRITE_F(type) extern __declspec(dllimport) type
196 # define LDAP_REWRITE_V(type) extern __declspec(dllimport) type
198 # define LDAP_REWRITE_F(type) extern type
199 # define LDAP_REWRITE_V(type) extern type
202 /* SLAPD (as a dynamic library exporting symbols) */
203 #if defined(_WIN32) && defined(SLAPD_IMPORT)
204 # define LDAP_SLAPD_F(type) extern __declspec(dllimport) type
205 # define LDAP_SLAPD_V(type) extern __declspec(dllimport) type
207 # define LDAP_SLAPD_F(type) extern type
208 # define LDAP_SLAPD_V(type) extern type
212 * C library. Mingw32 links with the dynamic C run-time library by default,
213 * so the explicit definition of CSTATIC will keep dllimport from
214 * being defined, if desired.
216 * MSVC defines the _DLL macro when the compiler is invoked with /MD or /MDd,
217 * which means the resulting object code will be linked with the dynamic
218 * C run-time library.
220 * Technically, it shouldn't be necessary to redefine any functions that
221 * the headers for the C library should already contain. Nevertheless, this
222 * is here as a safe-guard.
224 * TODO: Determine if these macros ever get expanded for Windows. If not,
225 * the declspec expansion can probably be removed.
227 #if (defined(__MINGW32__) && !defined(CSTATIC)) || \
228 (defined(_MSC_VER) && defined(_DLL))
229 # define LDAP_LIBC_F(type) extern __declspec(dllimport) type
230 # define LDAP_LIBC_V(type) extern __declspec(dllimport) type
232 # define LDAP_LIBC_F(type) extern type
233 # define LDAP_LIBC_V(type) extern type
236 #endif /* _LDAP_CDEFS_H */