@@ -133,35 +133,56 @@ typedef int (*secp256k1_nonce_function)(
133
133
# define SECP256K1_NO_BUILD
134
134
#endif
135
135
136
- /* Symbol visibility. See https://gcc.gnu.org/wiki/Visibility */
137
- /* DLL_EXPORT is defined internally for shared builds */
136
+ /* Symbol visibility. */
138
137
#if defined(_WIN32 ) || defined(__CYGWIN__ )
139
- # ifdef SECP256K1_BUILD
140
- # ifdef DLL_EXPORT
138
+ /* GCC for Windows (e.g., MinGW) and for Cygwin accept the __declspec syntax
139
+ * for MVSC compatibility, see "Microsoft Windows Function Attributes" in the
140
+ * GCC manual. Note that __attribute__ ((visibility("default"))) is not exactly
141
+ * equivalent to __declspec (dllexport), and as a result, we want the latter
142
+ * even on GCC, see https://gcc.gnu.org/wiki/Visibility. */
143
+ # if defined(SECP256K1_BUILD )
144
+ # if defined(DLL_EXPORT )
145
+ /* Building libsecp256k1 as a DLL. */
141
146
# define SECP256K1_API __declspec (dllexport)
142
147
# define SECP256K1_API_VAR extern __declspec (dllexport)
143
148
# endif
144
149
# elif defined(SECP256K1_IMPORT_AS_STATICLIB ) && defined(SECP256K1_IMPORT_AS_DLL )
145
150
# error "At most one of SECP256K1_IMPORT_AS_STATICLIB and SECP256K1_IMPORT_AS_DLL must be defined."
146
151
# elif defined(SECP256K1_IMPORT_AS_STATICLIB )
152
+ /* Linking against static libsecp256k1 requested explicitly. */
147
153
# define SECP256K1_API
148
154
# define SECP256K1_API_VAR extern
149
155
# elif defined(SECP256K1_IMPORT_AS_DLL )
156
+ /* Linking against libsecp256k1 DLL requested explicitly. */
150
157
# define SECP256K1_API __declspec (dllimport)
151
158
# define SECP256K1_API_VAR extern __declspec (dllimport)
152
- # elif defined _MSC_VER
159
+ # elif defined(_MSC_VER )
160
+ /* No method requested explicitly. The following works on MSVC for both
161
+ * static and dynamic linking, as long as if at least one function is
162
+ * imported (i.e., not only variables are imported), which should be the case
163
+ * for any meaningful program that uses the libsecp256k1 API. The drawback of
164
+ * the following is that it may provoke linker warnings LNK4217 and LNK4286.
165
+ * See "Windows DLLs" in the libtool manual. */
153
166
# define SECP256K1_API
154
167
# define SECP256K1_API_VAR extern __declspec (dllimport)
155
- # elif defined DLL_EXPORT
168
+ # elif defined(DLL_EXPORT )
169
+ /* No method requested explicitly and we're not on MSVC. We make an educated
170
+ * guess based on DLL_EXPORT: If the importing program is itself a DLL, then
171
+ * it is likely that it also wants to import libsecp256k1 as a DLL. If our
172
+ * guess is wrong, the user will need to make a specific request using the
173
+ * macros checked above. See "Windows DLLs" in the libtool manual. */
156
174
# define SECP256K1_API __declspec (dllimport)
157
175
# define SECP256K1_API_VAR extern __declspec (dllimport)
158
176
# endif
159
177
#endif
160
178
#ifndef SECP256K1_API
161
179
# if defined(__GNUC__ ) && (__GNUC__ >= 4 ) && defined(SECP256K1_BUILD )
180
+ /* Building libsecp256k1 on non-Windows using GCC or compatible. */
162
181
# define SECP256K1_API __attribute__ ((visibility ("default")))
163
182
# define SECP256K1_API_VAR extern __attribute__ ((visibility ("default")))
164
183
# else
184
+ /* Linking against libsecp256k1,
185
+ or building libsecp256k1 using an unknown compiler. */
165
186
# define SECP256K1_API
166
187
# define SECP256K1_API_VAR extern
167
188
# endif
0 commit comments