bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Jeffrey Walton <noloader@gmail.com>
To: Bruno Haible <bruno@clisp.org>
Cc: bug-gnulib@gnu.org
Subject: Re: crypto/gc-random: Fix link error on MSVC
Date: Sat, 30 May 2020 08:26:08 -0400	[thread overview]
Message-ID: <CAH8yC8mzzVjKK+=XBb0=S8K3=EdNRo6mh6z0qprZDC3XAE6hWw@mail.gmail.com> (raw)
In-Reply-To: <8420710.z7x3erh4Ic@omega>

On Sat, May 30, 2020 at 8:17 AM Bruno Haible <bruno@clisp.org> wrote:
>
> 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  <bruno@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)

On modern Windows systems you should use BCryptGenRandom for the
material. CryptGenRandom is deprecated.

Also see https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptgenrandom.

Jeff


      reply	other threads:[~2020-05-30 12:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-30 12:16 crypto/gc-random: Fix link error on MSVC Bruno Haible
2020-05-30 12:26 ` Jeffrey Walton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH8yC8mzzVjKK+=XBb0=S8K3=EdNRo6mh6z0qprZDC3XAE6hWw@mail.gmail.com' \
    --to=noloader@gmail.com \
    --cc=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).