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
diff --git a/src/event/modules/ngx_iocp_module.c b/src/event/modules/ngx_iocp_module.c
--- a/src/event/modules/ngx_iocp_module.c
+++ b/src/event/modules/ngx_iocp_module.c
@@ -242,17 +242,17 @@ ngx_int_t ngx_iocp_process_events(ngx_cy
ngx_event_ovlp_t *ovlp;
if (timer == NGX_TIMER_INFINITE) {
timer = INFINITE;
}
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "iocp timer: %M", timer);
- rc = GetQueuedCompletionStatus(iocp, &bytes, (LPDWORD) &key,
+ rc = GetQueuedCompletionStatus(iocp, &bytes, (PULONG_PTR) &key,
(LPOVERLAPPED *) &ovlp, (u_long) timer);
if (rc == 0) {
err = ngx_errno;
} else {
err = 0;
}
diff --git a/src/os/win32/ngx_win32_config.h b/src/os/win32/ngx_win32_config.h
--- a/src/os/win32/ngx_win32_config.h
+++ b/src/os/win32/ngx_win32_config.h
@@ -33,18 +33,17 @@
#include <winsock2.h>
#include <ws2tcpip.h> /* ipv6 */
#include <mswsock.h>
#include <shellapi.h>
#include <stddef.h> /* offsetof() */
#ifdef __GNUC__
-/* GCC MinGW's stdio.h includes sys/types.h */
-#define _OFF_T_
+#define _FILE_OFFSET_BITS 64
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <locale.h>
@@ -131,25 +130,31 @@ typedef int int32_t;
typedef unsigned short int uint16_t;
#define ngx_libc_cdecl
#endif
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
-#ifndef __WATCOMC__
+#ifdef __WATCOMC__
+/* do nothing */
+#elif defined(__GNUC__)
+#include <stdint.h>
+#else
typedef int intptr_t;
typedef u_int uintptr_t;
#endif
+#ifndef __GNUC__
/* Windows defines off_t as long, which is 32-bit */
-typedef __int64 off_t;
-#define _OFF_T_DEFINED
+typedef __int64 off64_t;
+#define _OFF64_T_DEFINED
+#endif
#ifdef __WATCOMC__
/* off_t is redefined by sys/types.h used by zlib.h */
#define __TYPES_H_INCLUDED
typedef int dev_t;
typedef unsigned int ino_t;
@@ -159,17 +164,19 @@ typedef unsigned int ino_t;
#define __TYPES_H
typedef int dev_t;
typedef unsigned int ino_t;
#endif
+#ifndef __GNUC__
typedef int ssize_t;
+#endif
typedef uint32_t in_addr_t;
typedef u_short in_port_t;
typedef int sig_atomic_t;
#define NGX_PTR_SIZE 4
#define NGX_SIZE_T_LEN (sizeof("-2147483648") - 1)
#define NGX_MAX_SIZE_T_VALUE 2147483647
diff --git a/src/os/win32/ngx_wsasend_chain.c b/src/os/win32/ngx_wsasend_chain.c
--- a/src/os/win32/ngx_wsasend_chain.c
+++ b/src/os/win32/ngx_wsasend_chain.c
@@ -29,17 +29,17 @@ ngx_wsasend_chain(ngx_connection_t *c, n
wev = c->write;
if (!wev->ready) {
return in;
}
/* the maximum limit size is the maximum u_long value - the page size */
- if (limit == 0 || limit > NGX_MAX_UINT32_VALUE - ngx_pagesize) {
+ if (limit == 0 || limit > (off_t) (NGX_MAX_UINT32_VALUE - ngx_pagesize)) {
limit = NGX_MAX_UINT32_VALUE - ngx_pagesize;
}
send = 0;
/*
* WSABUFs must be 4-byte aligned otherwise
* WSASend() will return undocumented WSAEINVAL error.
@@ -151,17 +151,17 @@ ngx_overlapped_wsasend_chain(ngx_connect
"wev->complete: %d", wev->complete);
if (!wev->complete) {
/* post the overlapped WSASend() */
/* the maximum limit size is the maximum u_long value - the page size */
- if (limit == 0 || limit > NGX_MAX_UINT32_VALUE - ngx_pagesize) {
+ if (limit == 0 || limit > (off_t) (NGX_MAX_UINT32_VALUE - ngx_pagesize)) {
limit = NGX_MAX_UINT32_VALUE - ngx_pagesize;
}
/*
* WSABUFs must be 4-byte aligned otherwise
* WSASend() will return undocumented WSAEINVAL error.
*/
_______________________________________________
nginx-devel mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx-devel