Skip to content

Commit 86a6ecd

Browse files
committed
build: Add SECP256K1_NO_EXPORTS option to avoid default visibility for static libs
autotools defines DLL_EXPORT for dll builds. CMake mimics this behavior and defines SECP256K1_DLL_EXPORT. This means that currently Windows builds only export their symbols for shared libraries, and all other platforms export for shared AND static. Unfortunately, there's no way to make autotools define a special variable when building for other platforms. CMake could define a variable for shared lib builds on all platforms, which the header could then use to decide whether or not to export symbols, but that would introduce a behavioral difference between the build-systems. Instead, provide an escape hatch via SECP256K1_NO_EXPORTS which can be used when building secp for non-Windows targets when exports are not desired (when building a static lib).
1 parent 9239447 commit 86a6ecd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/secp256k1.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ typedef int (*secp256k1_nonce_function)(
132132
# if defined(DLL_EXPORT) || defined(SECP256K1_DLL_EXPORT)
133133
/* Building libsecp256k1 as a DLL.
134134
* 1. If using Libtool, it defines DLL_EXPORT automatically.
135-
* 2. In other cases, SECP256K1_DLL_EXPORT must be defined. */
135+
* 2. If using CMake, it defines SECP256K1_DLL_EXPORT automatically. */
136136
# define SECP256K1_API extern __declspec (dllexport)
137137
# else
138138
/* Building libsecp256k1 as a static library on Windows.
@@ -153,7 +153,7 @@ typedef int (*secp256k1_nonce_function)(
153153
#endif
154154
#ifndef SECP256K1_API
155155
/* All cases not captured by the Windows-specific logic. */
156-
# if defined(__GNUC__) && (__GNUC__ >= 4) && defined(SECP256K1_BUILD)
156+
# if defined(__GNUC__) && (__GNUC__ >= 4) && defined(SECP256K1_BUILD) && !defined(SECP256K1_NO_EXPORTS)
157157
/* Building libsecp256k1 using GCC or compatible. */
158158
# define SECP256K1_API extern __attribute__ ((visibility ("default")))
159159
# else

0 commit comments

Comments
 (0)