socklen problems with Libgcrypt 1.2.4 on mingw32

Simon Josefsson simon at josefsson.org
Fri Feb 2 11:37:21 CET 2007


Hi!  Cross-compiling libgcrypt 1.2.4 to mingw32 fails:

checking for socklen_t... yes
...
make[2]: Entering directory `/home/jas/gnutls4win/build/libgcrypt-1.2.4/mpi'
if /bin/sh ../libtool --tag=CC --mode=compile i586-mingw32msvc-gcc -DHAVE_CONFIG_H -I. -I../../../src/libgcrypt-1.2.4/mpi -I.. -I../../../src/libgcrypt-1.2.4/src   -I/home/jas/gnutls4win/inst/include -g -O2 -Wall -MT mpi-add.lo -MD -MP -MF ".deps/mpi-add.Tpo" -c -o mpi-add.lo ../../../src/libgcrypt-1.2.4/mpi/mpi-add.c; \
        then mv -f ".deps/mpi-add.Tpo" ".deps/mpi-add.Plo"; else rm -f ".deps/mpi-add.Tpo"; exit 1; fi
 i586-mingw32msvc-gcc -DHAVE_CONFIG_H -I. -I../../../src/libgcrypt-1.2.4/mpi -I.. -I../../../src/libgcrypt-1.2.4/src -I/home/jas/gnutls4win/inst/include -g -O2 -Wall -MT mpi-add.lo -MD -MP -MF .deps/mpi-add.Tpo -c ../../../src/libgcrypt-1.2.4/mpi/mpi-add.c  -DDLL_EXPORT -DPIC -o .libs/mpi-add.o
In file included from ../../../src/libgcrypt-1.2.4/src/g10lib.h:36,
                 from ../../../src/libgcrypt-1.2.4/src/mpi.h:36,
                 from ../../../src/libgcrypt-1.2.4/mpi/mpi-internal.h:52,
                 from ../../../src/libgcrypt-1.2.4/mpi/mpi-add.c:31:
../../../src/libgcrypt-1.2.4/src/gcrypt.h:36: error: syntax error before "gcry_socklen_t"
../../../src/libgcrypt-1.2.4/src/gcrypt.h:36: warning: type defaults to `int' in declaration of `gcry_socklen_t'
../../../src/libgcrypt-1.2.4/src/gcrypt.h:36: warning: data definition has no type or storage class
In file included from ../../../src/libgcrypt-1.2.4/src/g10lib.h:36,
                 from ../../../src/libgcrypt-1.2.4/src/mpi.h:36,
                 from ../../../src/libgcrypt-1.2.4/mpi/mpi-internal.h:52,
                 from ../../../src/libgcrypt-1.2.4/mpi/mpi-add.c:31:
../../../src/libgcrypt-1.2.4/src/gcrypt.h:195: error: syntax error before "gcry_socklen_t"
../../../src/libgcrypt-1.2.4/src/gcrypt.h:196: error: syntax error before "gcry_socklen_t"
make[2]: *** [mpi-add.lo] Error 1

The problem is that m4/socklen.m4 do some thing which gcrypt.h doesn't
do, specifically:

      #elif HAVE_WS2TCPIP_H
      # include <ws2tcpip.h>
      #endif])])

This patch for gcrypt.h fixes the problem for me:

--- gcrypt.h~	2007-02-02 11:11:11.000000000 +0100
+++ gcrypt.h	2007-02-02 11:22:55.000000000 +0100
@@ -1,6 +1,6 @@
 /* gcrypt.h -  GNU cryptographic library interface            -*- c -*-
  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
- *               2004, 2006  Free Software Foundation, Inc.
+ *               2004, 2006, 2007  Free Software Foundation, Inc.
  *
  * This file is part of Libgcrypt.
  *
@@ -29,8 +29,10 @@
 #include <gpg-error.h>
 
 #include <sys/types.h>
-#ifndef _WIN32
-#include <sys/socket.h>
+#if defined _WIN32 || defined __WIN32__
+# include <ws2tcpip.h>
+#else
+# include <sys/socket.h>
 #endif /*!_WIN32*/
 
 typedef socklen_t gcry_socklen_t;

The change of CPP's symbols was based on Bruno Haible's analysis of
what WIN32 symbols are present on native/mingw32/cygwin, posted to the
gnulib list some time ago.

After fixing that, I get problems for src/secmem.c and src/ath.c:

make[2]: Entering directory `/home/jas/gnutls4win/build/libgcrypt-1.2.4/src'
if /bin/sh ../libtool --tag=CC --mode=compile i586-mingw32msvc-gcc -DHAVE_CONFIG_H -I. -I../../../src/libgcrypt-1.2.4/src -I..    -I/home/jas/gnutls4win/inst/include -g -O2 -Wall -MT libgcrypt_la-secmem.lo -MD -MP -MF ".deps/libgcrypt_la-secmem.Tpo" -c -o libgcrypt_la-secmem.lo `test -f 'secmem.c' || echo '../../../src/libgcrypt-1.2.4/src/'`secmem.c; \
        then mv -f ".deps/libgcrypt_la-secmem.Tpo" ".deps/libgcrypt_la-secmem.Plo"; else rm -f ".deps/libgcrypt_la-secmem.Tpo"; exit 1; fi
 i586-mingw32msvc-gcc -DHAVE_CONFIG_H -I. -I../../../src/libgcrypt-1.2.4/src -I.. -I/home/jas/gnutls4win/inst/include -g -O2 -Wall -MT libgcrypt_la-secmem.lo -MD -MP -MF .deps/libgcrypt_la-secmem.Tpo -c ../../../src/libgcrypt-1.2.4/src/secmem.c  -DDLL_EXPORT -DPIC -o .libs/libgcrypt_la-secmem.o
In file included from ../../../src/libgcrypt-1.2.4/src/secmem.c:40:
../../../src/libgcrypt-1.2.4/src/ath.h:83: error: syntax error before "socklen_t"
../../../src/libgcrypt-1.2.4/src/secmem.c: In function `init_pool':
../../../src/libgcrypt-1.2.4/src/secmem.c:340: warning: implicit declaration of function `getpagesize'
make[2]: *** [libgcrypt_la-secmem.lo] Error 1

These patches seem to fix that:

--- ath.c~	2005-07-29 15:45:42.000000000 +0200
+++ ath.c	2007-02-02 11:27:26.000000000 +0100
@@ -1,5 +1,5 @@
 /* ath.c - Thread-safeness library.
-   Copyright (C) 2002, 2003, 2004 g10 Code GmbH
+   Copyright (C) 2002, 2003, 2004, 2007 g10 Code GmbH
 
    This file is part of Libgcrypt.
  
@@ -35,6 +35,7 @@
 #endif
 #include <errno.h>
 
+#include "g10lib.h"
 #include "ath.h"
 
 
--- secmem.c~	2007-02-01 19:04:30.000000000 +0100
+++ secmem.c	2007-02-02 11:28:31.000000000 +0100
@@ -1,6 +1,6 @@
 /* secmem.c  -	memory allocation from a secure heap
  * Copyright (C) 1998, 1999, 2000, 2001, 2002,
- *               2003 Free Software Foundation, Inc.
+ *               2003, 2007 Free Software Foundation, Inc.
  *
  * This file is part of Libgcrypt.
  *
@@ -37,8 +37,8 @@
 #endif
 #endif
 
-#include "ath.h"
 #include "g10lib.h"
+#include "ath.h"
 #include "secmem.h"
 
 #if defined (MAP_ANON) && ! defined (MAP_ANONYMOUS)

With these changes, libgcrypt 1.2.4 build fine for me under mingw32.

Thanks,
Simon



More information about the Gcrypt-devel mailing list