Unable to build GDB on Windows

Eli Zaretskii eliz@gnu.org
Mon Sep 28 14:43:43 GMT 2020

> Date: Mon, 28 Sep 2020 17:25:25 +0300
> From: Eli Zaretskii via Gdb <gdb@sourceware.org>
> Cc: gdb@sourceware.org
> > From: Simon Cook <simon.cook@embecosm.com>
> > Date: Mon, 28 Sep 2020 14:47:25 +0100
> > 
> > I've been trying to build top of tree GDB on Windows (natively under
> > the MSYS2 environment), and haven't been able to link successfully due
> > to undefined symbols after linking against gnulib:
> > 
> >     CXXLD  gdb.exe
> >   ../gnulib/import/libgnu.a(getrandom.o): In function `getrandom':
> >   C:\msys64s\home\simon\work\b\gnulib\import/../../../binutils-gdb/gnulib/import/getrandom.c:129:
> > undefined reference to `BCryptGenRandom'
> >   collect2.exe: error: ld returned 1 exit status
> > 
> > Reading through the source file and gnulib/import/m4/getrandom.m4, it
> > suggests that in my case if bcrypt can be guaranteed to be present
> > then I should add -lbcrypt to my linker flags to resolve these
> > references, and indeed if I execute the failing gdb link command and
> > add -lbcrypt at the end then my link succeeds.

Btw, looking at Gnulib's getrandom.c, my conclusion is that a GDB
built on Windows 7 and later will be unable to run on older versions
of Windows, because it will have a static dependency on bcrypt.dll and
the BCryptGenRandom function from that DLL.  IOW, such a GDB will
refuse to run on older Windows systems.

OTOH, if you build on Windows before 7, the produced binary will be
able to run on newer versions of Windows by dynamically loading
bcrypt.dll (when available) at run time, and using a fallback

Perhaps no one cares about Windows 7 and older anymore, but I just
wanted to say this FTR, in case someone bumps into such a problem.

More information about the Gdb mailing list