Subject: compile errors and missing dependencies when building in mingw32 on windows

From: ar <[email-masked]>
Date: Sat, 25 Apr 2020 09:17:19 +0000 (UTC)

I'm trying to compile guile 3.0.2 on a windows 32bit machine using Mingw32.
I was able to successfully run the configure script with no errors. FYI I had to compile the following libraries from source in order for the configure script to finish because for some reason the libraries installed by pacman didn't work.- libtool 2.4.6- libunistring 0.9.10- libffi 3.3- libgc 8.0.4- readline 8.0- termcap 1.3.1
When I try to build I get the following error when compiling poll.lo
Error 1:D:/msys32/mingw32/i686-w64-mingw32/include/winsock2.h:1185:16: error: redefinitipollfd'
 1185 | typedef struct pollfd {
      |                ^~~~~~
In file included from poll.c:32:
./poll.h:405:8: note: originally defined here
  405 | struct pollfd
      |        ^~~~~~
poll.c:329:1: error: conflicting types for 'poll'
  329 | poll (struct pollfd *pfd, nfds_t nfd, int timeout)
      | ^~~~
In file included from poll.c:32:
./poll.h:435:1: note: previous declaration of 'poll' was here
  435 | _GL_FUNCDECL_SYS (poll, int, (struct pollfd *pfd, nfds_t nfd, int timeou
      | ^~~~~~~~~~~~~~~~
make[4]: *** [Makefile:2128: poll.lo] Error 1
Fix 1:My solution to get around this was to comment the definition of struct pollfd and the declaration of GL_FUNCDECL_SYS (poll ...

Error 2:
The next error is in libguile/socket.c
  SNARF  socket.x
socket.c:43:10: fatal error: netinet/tcp.h: No such file or directory
   43 | #include <netinet/tcp.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.

Fix 2:I commented the includes <netinet/…> and replaced with #include <winsock2.h>
I noticed that lib/socket.c correctly includes <winsock.h> instead of <netinet/tcp.h>

Error 3:The next error is 
jit.c:29:10: fatal error: sys/mman.h: No such file or directory
   29 | #include <sys/mman.h>
      |          ^~~~~~~~~~~~

Fix 3:so I downloaded the library from https://github.com/witwall/mman-win32and configured it to install in /mingw32.   This seemed to work.

Error 4:
Next errorIn file included from posix.c:63:
posix-w32.h:67:9: error: unknown type name 'DWORD_PTR'
   67 | typedef DWORD_PTR cpu_set_t;
Fix 4:so added #include <windef.h>

Error 5:posix-w32.h:73:13: error: expected ';' before 'int'
   73 | SCM_INTERNAL int uname (struct utsname * uts);
      |             ^~~~
Fix 5:so added #include "libguile/scm.h"
Error 6:Finally, get undefined functions error from the linkerD:/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: .libs/libguile_3.0_la-jit.o: in function `allocate_code_arena':
C:\Users\\Downloads\guile-3.0.2\libguile/jit.c:1333: undefined reference to `mmap'
D:/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: .libs/libguile_3.0_la-jit.o: in function `emit_code':
C:\Users\\Downloads\guile-3.0.2\libguile/jit.c:1394: undefined reference to `munmap'
D:/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: ../lib/.libs/libgnu.a(timegm.o): in function `timegm':
C:\Users\\Downloads\guile-3.0.2\lib/timegm.c:39: undefined reference to `mktime_internal'

And at this point, I tried every way I could to add the path to the libmann.a but I couldn't make it work.

It seems the errors are in the configure scripts and in the list of required dependencies.  The undefined reference to mmap and munmap has to be something silly that I'm missing.  The next big mystery is the mktime_internal.

Thanks,

El amor a la patria tiene que transformarse en acción y ésta tiene que ser acción para el bien común. (Adalexis Rios- mi madre)