Skip to content

Commit 6177b8a

Browse files
committed
build: Use SECP256K1_STATICLIB macro instead of warning suppressions
This change allows the user to define the `SECP256K1_STATICLIB` macro instead of ignoring MSVC linker warnings LNK4217 and LNK4286.
1 parent 67214f5 commit 6177b8a

File tree

4 files changed

+5
-11
lines changed

4 files changed

+5
-11
lines changed

Makefile.am

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ endif
153153
if USE_EXAMPLES
154154
noinst_PROGRAMS += ecdsa_example
155155
ecdsa_example_SOURCES = examples/ecdsa.c
156-
ecdsa_example_CPPFLAGS = -I$(top_srcdir)/include
156+
ecdsa_example_CPPFLAGS = -I$(top_srcdir)/include -DSECP256K1_STATICLIB
157157
ecdsa_example_LDADD = libsecp256k1.la
158158
ecdsa_example_LDFLAGS = -static
159159
if BUILD_WINDOWS
@@ -163,7 +163,7 @@ TESTS += ecdsa_example
163163
if ENABLE_MODULE_ECDH
164164
noinst_PROGRAMS += ecdh_example
165165
ecdh_example_SOURCES = examples/ecdh.c
166-
ecdh_example_CPPFLAGS = -I$(top_srcdir)/include
166+
ecdh_example_CPPFLAGS = -I$(top_srcdir)/include -DSECP256K1_STATICLIB
167167
ecdh_example_LDADD = libsecp256k1.la
168168
ecdh_example_LDFLAGS = -static
169169
if BUILD_WINDOWS
@@ -174,7 +174,7 @@ endif
174174
if ENABLE_MODULE_SCHNORRSIG
175175
noinst_PROGRAMS += schnorr_example
176176
schnorr_example_SOURCES = examples/schnorr.c
177-
schnorr_example_CPPFLAGS = -I$(top_srcdir)/include
177+
schnorr_example_CPPFLAGS = -I$(top_srcdir)/include -DSECP256K1_STATICLIB
178178
schnorr_example_LDADD = libsecp256k1.la
179179
schnorr_example_LDFLAGS = -static
180180
if BUILD_WINDOWS

configure.ac

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,6 @@ AC_DEFUN([SECP_TRY_APPEND_DEFAULT_CFLAGS], [
127127
SECP_TRY_APPEND_CFLAGS([-wd4267], $1) # Disable warning C4267 "'var' : conversion from 'size_t' to 'type', possible loss of data".
128128
# Eliminate deprecation warnings for the older, less secure functions.
129129
CPPFLAGS="-D_CRT_SECURE_NO_WARNINGS $CPPFLAGS"
130-
# We pass -ignore:4217 to the MSVC linker to suppress warning 4217 when
131-
# importing variables from a statically linked secp256k1.
132-
# (See the libtool manual, section "Windows DLLs" for background.)
133-
# Unfortunately, libtool tries to be too clever and strips "-Xlinker arg"
134-
# into "arg", so this will be " -Xlinker -ignore:4217" after stripping.
135-
LDFLAGS="-Xlinker -Xlinker -Xlinker -ignore:4217 $LDFLAGS"
136130
fi
137131
])
138132
SECP_TRY_APPEND_DEFAULT_CFLAGS(SECP_CFLAGS)

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ target_link_libraries(example INTERFACE
77
$<$<PLATFORM_ID:Windows>:bcrypt>
88
)
99
if(NOT BUILD_SHARED_LIBS AND MSVC)
10-
target_link_options(example INTERFACE /IGNORE:4217)
10+
target_compile_definitions(example INTERFACE SECP256K1_STATICLIB)
1111
endif()
1212

1313
add_executable(ecdsa_example ecdsa.c)

include/secp256k1.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ typedef int (*secp256k1_nonce_function)(
140140
# define SECP256K1_API __declspec (dllexport)
141141
# define SECP256K1_API_VAR extern __declspec (dllexport)
142142
# endif
143-
# elif defined _MSC_VER
143+
# elif defined(_MSC_VER) && !defined(SECP256K1_STATICLIB)
144144
# define SECP256K1_API
145145
# define SECP256K1_API_VAR extern __declspec (dllimport)
146146
# elif defined DLL_EXPORT

0 commit comments

Comments
 (0)