[PATCH] Support cross compiling with MinGW-w64 on Debian GNU/Linux

Kouhei Sutou kou at cozmixng.org
Sat Oct 11 01:41:23 UTC 2014


Hi,

Could anyone review the patch?

In <20141004.195156.801414609668336877.kou at cozmixng.org>
  "[PATCH] Support cross compiling with MinGW-w64 on Debian GNU/Linux" on Sat, 04 Oct 2014 19:51:56 +0900 (JST),
  Kouhei Sutou <kou at cozmixng.org> wrote:

> Hi,
> 
> I'm trying cross compiling nginx for Windows on Debian
> GNU/Linux. The current nginx doesn't support it.
> I created a patch to do it. With the attached patch, I can
> cross compile nginx for Windows on Debian GNU/Linux.
> Please review the attached patch.
> 
> The current status (without patch)
> ----------------------------------
> 
> Compiler:
> 
>   % x86_64-w64-mingw32-gcc --version
>   x86_64-w64-mingw32-gcc (GCC) 4.9.1
>   Copyright (C) 2014 Free Software Foundation, Inc.
>   This is free software; see the source for copying conditions.  There is NO
>   warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> Configure command line:
> 
>   % auto/configure \
>       --prefix=/tmp/local \
>       --crossbuild=win32 \
>       --with-cc=x86_64-w64-mingw32-gcc \
>       --with-cpp=x86_64-w64-mingw32-c++ \
>       --without-http_rewrite_module \
>       --without-http_gzip_module
> 
> Build result:
> 
>   % make
>   make -f objs/Makefile
>   make[1]: Entering directory '/home/kou/work/c/nginx.win32'
>   x86_64-w64-mingw32-gcc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/win32 -I objs \
>           -o objs/src/core/nginx.o \
>           src/core/nginx.c
>   In file included from /usr/share/mingw-w64/include/stdio.h:80:0,
>                    from src/os/win32/ngx_win32_config.h:45,
>                    from src/core/ngx_config.h:38,
>                    from src/core/nginx.c:8:
>   /usr/share/mingw-w64/include/_mingw_off_t.h:26:9: error: unknown type name ‘off32_t’
>    typedef off32_t off_t;
>            ^
>   In file included from src/os/win32/ngx_win32_config.h:45:0,
>                    from src/core/ngx_config.h:38,
>                    from src/core/nginx.c:8:
>   /usr/share/mingw-w64/include/stdio.h:463:28: error: unknown type name ‘_off_t’
>      int fseeko(FILE* stream, _off_t offset, int whence);
>                               ^
>   /usr/share/mingw-w64/include/stdio.h:474:3: error: unknown type name ‘_off_t’
>      _off_t ftello(FILE * stream);
>      ^
>   In file included from src/core/ngx_config.h:38:0,
>                    from src/core/nginx.c:8:
>   src/os/win32/ngx_win32_config.h:140:29: error: conflicting types for ‘intptr_t’
>    typedef int                 intptr_t;
>                                ^
>   In file included from /usr/share/mingw-w64/include/windows.h:9:0,
>                    from src/os/win32/ngx_win32_config.h:28,
>                    from src/core/ngx_config.h:38,
>                    from src/core/nginx.c:8:
>   /usr/share/mingw-w64/include/_mingw.h:399:35: note: previous declaration of ‘intptr_t’ was here
>    __MINGW_EXTENSION typedef __int64 intptr_t;
>                                      ^
>   In file included from src/core/ngx_config.h:38:0,
>                    from src/core/nginx.c:8:
>   src/os/win32/ngx_win32_config.h:141:29: error: conflicting types for ‘uintptr_t’
>    typedef u_int               uintptr_t;
>                                ^
>   In file included from /usr/share/mingw-w64/include/windows.h:9:0,
>                    from src/os/win32/ngx_win32_config.h:28,
>                    from src/core/ngx_config.h:38,
>                    from src/core/nginx.c:8:
>   /usr/share/mingw-w64/include/_mingw.h:412:44: note: previous declaration of ‘uintptr_t’ was here
>    __MINGW_EXTENSION typedef unsigned __int64 uintptr_t;
>                                               ^
>   In file included from src/core/ngx_config.h:38:0,
>                    from src/core/nginx.c:8:
>   src/os/win32/ngx_win32_config.h:146:29: error: conflicting types for ‘off_t’
>    typedef __int64             off_t;
>                                ^
>   In file included from /usr/share/mingw-w64/include/stdio.h:80:0,
>                    from src/os/win32/ngx_win32_config.h:45,
>                    from src/core/ngx_config.h:38,
>                    from src/core/nginx.c:8:
>   /usr/share/mingw-w64/include/_mingw_off_t.h:26:17: note: previous declaration of ‘off_t’ was here
>    typedef off32_t off_t;
>                    ^
>   In file included from src/core/ngx_config.h:38:0,
>                    from src/core/nginx.c:8:
>   src/os/win32/ngx_win32_config.h:167:29: error: conflicting types for ‘ssize_t’
>    typedef int                 ssize_t;
>                                ^
>   In file included from /usr/share/mingw-w64/include/windows.h:9:0,
>                    from src/os/win32/ngx_win32_config.h:28,
>                    from src/core/ngx_config.h:38,
>                    from src/core/nginx.c:8:
>   /usr/share/mingw-w64/include/_mingw.h:387:35: note: previous declaration of ‘ssize_t’ was here
>    __MINGW_EXTENSION typedef __int64 ssize_t;
>                                      ^
>   objs/Makefile:323: recipe for target 'objs/src/core/nginx.o' failed
>   make[1]: *** [objs/src/core/nginx.o] Error 1
>   make[1]: Leaving directory '/home/kou/work/c/nginx.win32'
>   Makefile:8: recipe for target 'build' failed
>   make: *** [build] Error 2
> 
> 
> How to solve
> ------------
> 
> I use the system type definitions instead of custom type
> definitions for off_t, intptr_t and ssize_t to solve the
> errors.
> 
> "#define _FILE_OFFSET_BITS 64" is for defining off_t as a
> 64bit type. (nginx requires off_t as a 64bit type.)
> 
> See the attached patch for details.
> 
> Note
> ----
> 
> The main change is the change for
> src/os/win32/ngx_win32_config.h.
> 
> The changes of the followings are just trivial build errors:
> 
>   * src/event/modules/ngx_iocp_module.c
>   * src/os/win32/ngx_wsasend_chain.c
> 
> The change of src/event/modules/ngx_iocp_module.c is for
> fixing the following warning:
> 
>   x86_64-w64-mingw32-gcc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/win32 -I objs \
>           -o objs/src/event/modules/ngx_iocp_module.o \
>           src/event/modules/ngx_iocp_module.c
>   src/event/modules/ngx_iocp_module.c: In function 'ngx_iocp_process_events':
>   src/event/modules/ngx_iocp_module.c:250:10: error: passing argument 3 of 'GetQueuedCompletionStatus' from incompatible pointer type [-Werror]
>        rc = GetQueuedCompletionStatus(iocp, &bytes, (LPDWORD) &key,
>             ^
>   In file included from /usr/share/mingw-w64/include/winbase.h:21:0,
>                    from /usr/share/mingw-w64/include/windows.h:70,
>                    from src/os/win32/ngx_win32_config.h:28,
>                    from src/core/ngx_config.h:38,
>                    from src/event/modules/ngx_iocp_module.c:8:
>   /usr/share/mingw-w64/include/ioapiset.h:20:29: note: expected 'PULONG_PTR' but argument is of type 'DWORD *'
>      WINBASEAPI WINBOOL WINAPI GetQueuedCompletionStatus (HANDLE CompletionPort, LPDWORD lpNumberOfBytesTransferred, PULONG_PTR lpCompletionKey, LPOVERLAPPED *lpOverlapped, DWORD dwMilliseconds);
>                                ^
>   cc1: all warnings being treated as errors
> 
> GetQueuedCompletionStatus() document on MSDN says the
> following signature:
> 
>   http://msdn.microsoft.com/en-us/library/windows/desktop/aa364986.aspx
> 
>   BOOL WINAPI GetQueuedCompletionStatus(
>     _In_   HANDLE CompletionPort,
>     _Out_  LPDWORD lpNumberOfBytes,
>     _Out_  PULONG_PTR lpCompletionKey,
>     _Out_  LPOVERLAPPED *lpOverlapped,
>     _In_   DWORD dwMilliseconds
>   );
> 
> In the latest specification, the type of the third argument
> (lpCompletionKey) is PULONG_PTR not LPDWORD. So the attached
> patch casts to PULONG_PTR instead of LPDWORD.
> 
> 
> The change of src/os/win32/ngx_wsasend_chain.c is for
> fixing the following warnings:
> 
>   x86_64-w64-mingw32-gcc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/win32 -I objs \
>           -o objs/src/os/win32/ngx_wsasend_chain.o \
>           src/os/win32/ngx_wsasend_chain.c
>   src/os/win32/ngx_wsasend_chain.c: In function 'ngx_wsasend_chain':
>   src/os/win32/ngx_wsasend_chain.c:37:29: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
>        if (limit == 0 || limit > NGX_MAX_UINT32_VALUE - ngx_pagesize) {
>                                ^
>   src/os/win32/ngx_wsasend_chain.c: In function 'ngx_overlapped_wsasend_chain':
>   src/os/win32/ngx_wsasend_chain.c:159:33: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
>            if (limit == 0 || limit > NGX_MAX_UINT32_VALUE - ngx_pagesize) {
>                                    ^
>   cc1: all warnings being treated as errors
>   objs/Makefile:673: recipe for target 'objs/src/os/win32/ngx_wsasend_chain.o' failed
> 
> 
> 
> I don't test the patch with Visual Studio. Sorry.
> I hope that someone try the patch with Visual Studio.
> 
> 
> Thanks,
> --
> kou


More information about the nginx-devel mailing list