[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems compiling 'getrandom' with MinGW

From: Eli Zaretskii
Subject: Problems compiling 'getrandom' with MinGW
Date: Sun, 28 Jun 2020 18:39:41 +0300

The current version of Gnulib's 'getrandom' has a couple of problems
when compiled with MinGW:

1. It assumes that the header bcrypt.h is always available.  This is
true for MinGW64, but not for mingw.org's MinGW.  A proposed patch to
allow the code be compiled without bcrypt.h is below, it is required
in Emacs because Emacs still supports versions of Windows older than

2. It causes the calling program to be linked against bcrypt.dll if
that library is available at build time.  This will cause problems if
the produced program is then copied to a system where bcrypt.dll is
not available, because the program will refuse to start.  Since the
code to dynamically load bcrypt.dll is already in getrandom.c, I
suggest to leave only it, and remove the possibility of linking
against the DLL -- it is IMO more trouble than help.  (In Emacs, I
needed to set gl_cv_lib_assume_bcrypt=no to avoid producing such
problematic binaries, but most people won't look so close at the code,
and will not understand the consequences.)

Here's the patch I propose to let getrandom.c compile for versions of
Windows older than Vista:

diff --git a/lib/getrandom.c b/lib/getrandom.c
index f0b3f53..112c100 100644
--- a/lib/getrandom.c
+++ b/lib/getrandom.c
@@ -29,7 +29,13 @@
 #if defined _WIN32 && ! defined __CYGWIN__
 # define WIN32_LEAN_AND_MEAN
 # include <windows.h>
-# include <bcrypt.h>
+# if _WIN32_WINNT >= 0x0600
+#  include <bcrypt.h>
+# else
+   typedef LONG NTSTATUS;
+   typedef void *BCRYPT_ALG_HANDLE;
+# endif
 #  include <wincrypt.h>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]