Welcome! Log In Create A New Profile

Advanced

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

Kouhei Sutou
October 04, 2014 06:54AM
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
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

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

Kouhei Sutou 2987 October 04, 2014 06:54AM

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

Maxim Dounin 742 October 08, 2014 10:26AM

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

Kouhei Sutou 579 October 11, 2014 08:30AM

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

Maxim Dounin 591 October 13, 2014 08:24PM

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

Kouhei Sutou 684 October 14, 2014 09:44AM

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

Maxim Dounin 505 October 14, 2014 10:12AM

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

Kouhei Sutou 666 October 14, 2014 11:24AM

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

Maxim Dounin 380 October 14, 2014 12:12PM

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

Kouhei Sutou 428 October 15, 2014 08:22AM

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

Maxim Dounin 542 October 17, 2014 10:46AM

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

Kouhei Sutou 428 October 17, 2014 11:44AM

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

Kouhei Sutou 458 October 27, 2014 11:02AM

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

Maxim Dounin 1023 October 27, 2014 01:48PM

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

Kouhei Sutou 615 October 28, 2014 09:06AM

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

Maxim Dounin 440 October 28, 2014 09:40AM

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

Kouhei Sutou 541 October 28, 2014 09:46AM

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

Kouhei Sutou 1325 October 10, 2014 09:42PM

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

Valentin V. Bartenev 524 October 11, 2014 05:18AM

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

Kouhei Sutou 460 October 11, 2014 08:30AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 160
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready