A testdir for module 'crypto/gc-random' produces a link error on MSVC 14: libgnu.a(gc-gnulib.obj) : error LNK2019: unresolved external symbol __imp_CryptAcquireContextA referenced in function gc_init libgnu.a(gc-gnulib.obj) : error LNK2019: unresolved external symbol __imp_CryptReleaseContext referenced in function gc_init libgnu.a(gc-gnulib.obj) : error LNK2019: unresolved external symbol __imp_CryptGenRandom referenced in function randomize test-gc.exe : fatal error LNK1120: 3 unresolved externals
This patch fixes it. 2020-05-30 Bruno Haible <br...@clisp.org> crypto/gc-random: Fix link error on MSVC. * m4/gc-random.m4 (gl_GC_RANDOM): Set LIB_GC_RANDOM. * modules/crypto/gc-random (Link): New section. * modules/crypto/gc-tests (Makefile.am): Link test-gc against $(LIB_GC_RANDOM). diff --git a/m4/gc-random.m4 b/m4/gc-random.m4 index 09483da..de9c1bb 100644 --- a/m4/gc-random.m4 +++ b/m4/gc-random.m4 @@ -1,4 +1,4 @@ -# gc-random.m4 serial 6 +# gc-random.m4 serial 7 dnl Copyright (C) 2005-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -9,7 +9,7 @@ AC_DEFUN([gl_GC_RANDOM], # Devices with randomness. # FIXME: Are these the best defaults? - AC_REQUIRE([AC_CANONICAL_HOST])dnl + AC_REQUIRE([AC_CANONICAL_HOST]) case "$host_os" in *openbsd* | *mirbsd*) @@ -84,4 +84,12 @@ AC_DEFUN([gl_GC_RANDOM], [defined to the name of the pseudo random device]) AC_DEFINE_UNQUOTED([NAME_OF_NONCE_DEVICE], ["$NAME_OF_NONCE_DEVICE"], [defined to the name of the unpredictable nonce device]) + + case $host_os in + mingw*) + LIB_GC_RANDOM='-ladvapi32' ;; + *) + LIB_GC_RANDOM= ;; + esac + AC_SUBST([LIB_GC_RANDOM]) ]) diff --git a/modules/crypto/gc-random b/modules/crypto/gc-random index 2f17871..2ffec7c 100644 --- a/modules/crypto/gc-random +++ b/modules/crypto/gc-random @@ -16,6 +16,9 @@ Makefile.am: Include: "gc.h" +Link: +$(LIB_GC_RANDOM) + License: LGPLv2+ diff --git a/modules/crypto/gc-tests b/modules/crypto/gc-tests index 7b153d1..f3da986 100644 --- a/modules/crypto/gc-tests +++ b/modules/crypto/gc-tests @@ -8,4 +8,4 @@ configure.ac: Makefile.am: TESTS += test-gc check_PROGRAMS += test-gc -test_gc_LDADD = $(LDADD) @LIB_CRYPTO@ +test_gc_LDADD = $(LDADD) @LIB_CRYPTO@ $(LIB_GC_RANDOM)