Building libnettle on MS-Windows

Eli Zaretskii eliz at gnu.org
Sat Jan 7 21:08:48 CET 2012


About a week ago, I built libnettle 2.4 on MS-Windows using the MinGW
tools.  While doing that, I found a few problems; this message reports
them.

For the record, I configured using " --disable-openssl --enable-shared".
This was suggested by the GnuTLS README file; as I needed libnettle to
build GnuTLS, I followed that advice.

Problem #1: Compiler warnings while compiling cbc.c:

     cbc.c: In function `nettle_cbc_decrypt':
     cbc.c:101: warning: implicit declaration of function `alloca'
     cbc.c:101: warning: nested extern declaration of `alloca'

   I fixed this by adding this to config.h.in:

     /* Needed for alloca on MinGW */
     # if HAVE_MALLOC_H
     #  include <malloc.h>
     # endif

   malloc.h in MinGW defines alloca to the GCC builtin; if the above
   is absent, the compiler falls back on "char *alloca()" which causes
   the warnings.

Problem #2: "make install" incorrectly copies the DLL files into
lib/*.dll.a.  *.dll.a are the Windows import libraries for using
during the link stage; the *.dll dynamic libraries themselves should
be copied into the $(bindir) directory.

   My solution was to add commands to corresponding recipes that cater
   to Windows, where *_SONAME variables are empty:

     install-shared-hogweed: $(LIBHOGWEED_FORLINK)
	     $(MKDIR_P) $(DESTDIR)$(libdir)
	     $(MKDIR_P) $(DESTDIR)$(bindir)
	     [ -z "$(LIBHOGWEED_SONAME)" ] \
		     && $(INSTALL_DATA) $(LIBHOGWEED_FORLINK) $(DESTDIR)$(bindir)
	     [ -z "$(LIBHOGWEED_SONAME)" ] \
		     && $(INSTALL_DATA) $(LIBHOGWEED_FILE) $(DESTDIR)$(libdir)
	     [ -z "$(LIBHOGWEED_SONAME)" ] \
		     || $(INSTALL_DATA) $(LIBHOGWEED_FORLINK) $(DESTDIR)$(libdir)/$(LIBHOGWEED_FILE)
	     [ -z "$(LIBHOGWEED_SONAME)" ] \
		     || (cd $(DESTDIR)$(libdir) \
		     && $(LN_S) $(LIBHOGWEED_FILE) $(LIBHOGWEED_SONAME) \
		     && $(LN_S) $(LIBHOGWEED_FILE) $(LIBHOGWEED_FORLINK))

Problem #3: Tests crash because they don't find libhogweed-2-1.dll.  This is
because Makefile uses "ln -sf" to create .lib/*.dll.

   Solution: add LN_S variable to Makefile.in, and then re-run the
   build with "make LN_S='cp -prf'.  Also, add this command to the
   recipes that build shared libraries:

	[ -z "$(LIBNETTLE_SONAME)" ] && (cd .lib \
          && $(LN_S) ../$(LIBNETTLE_FORLINK) $(LIBNETTLE_FORLINK))

   so that the DLLs are copied to .lib/ under the same name.

Problem #4: Tests in `examples' crash, cannot find libhogweed-2-1.

   Solution: add ../.lib to PATH, like testsuite/Makefile.in does.

Problem #5: testsuite/pkcs1-conv fails due to CRLF vs LF issue in compared
files (MinGW programs produce text files where each line ends in CRLF,
while the test expects the Unix-style LF-only end-of-line format).

   Solution: add --strip-trailing-cr switch to diff.

Problem #6: testsuite/sexp-conv fails due to CRLF vs LF issue in compared
files.

   Solution: use "diff --strip-trailing-cr" instead of "cmp".

Problem #7: examples/setup-env fails because it tries to read from
rsa-decrypt, which doesn't exist.  It should instead read from
rsa-decrypt.exe.

  Solution: fix setup-env to check which program file is actually
  present and read from that.

  A similar problem is in examples/rsa-encrypt-test.

Problem #8: examples/rsa-encrypt-test fails because rsa-encrypt.c and
rsa-decrypt.c read/write binary data from stdin to stdout, but do
not set these streams to binary mode.

  To solve this, I added code to the test programs to use binary
  mode.  Let me know if you want me to submit patches for that.

Last, but not least: thanks for developing and maintaining libnettle!


More information about the nettle-bugs mailing list