New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile zlib on windows nano #268

Open
atmosx opened this Issue May 29, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@atmosx
Copy link

atmosx commented May 29, 2017

Hello,

I'm trying to compile zlib on windows nano server. This platform is 64bit version only. Here are the steps:

Administrator@WIN-J4M9KOMET5D  /c/jenkins/workspace/win64/zlib-1.2.11
$ ./configure --64
Checking for gcc...
Checking for shared library support...
Building shared library libz.so.1.2.11 with gcc.
Checking for size_t... Yes.
Checking for off64_t... No.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... No.

Administrator@WIN-J4M9KOMET5D  /c/jenkins/workspace/win64/zlib-1.2.11
$ make -f win32/Makefile.gcc
gcc  -O3 -Wall -c -o adler32.o adler32.c
gcc  -O3 -Wall -c -o compress.o compress.c
gcc  -O3 -Wall -c -o crc32.o crc32.c
gcc  -O3 -Wall -c -o deflate.o deflate.c
gcc  -O3 -Wall -c -o gzclose.o gzclose.c
gcc  -O3 -Wall -c -o gzlib.o gzlib.c
gzlib.c: In function 'gz_open':
gzlib.c:243:20: warning: implicit declaration of function '_wopen' [-Wimplicit-function-declaration]
         fd == -2 ? _wopen(path, oflag, 0666) :
                    ^~~~~~
gcc  -O3 -Wall -c -o gzread.o gzread.c
gcc  -O3 -Wall -c -o gzwrite.o gzwrite.c
gcc  -O3 -Wall -c -o infback.o infback.c
gcc  -O3 -Wall -c -o inffast.o inffast.c
gcc  -O3 -Wall -c -o inflate.o inflate.c
gcc  -O3 -Wall -c -o inftrees.o inftrees.c
gcc  -O3 -Wall -c -o trees.o trees.c
gcc  -O3 -Wall -c -o uncompr.o uncompr.c
gcc  -O3 -Wall -c -o zutil.o zutil.c
ar rcs libz.a adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o gzwrite.o infback.o inffast.o inflate.o
inftrees.o trees.o uncompr.o zutil.o
gcc -shared -Wl,--out-implib,libz.dll.a  \
-o zlib1.dll win32/zlib.def adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o gzwrite.o infback.o inffas
t.o inflate.o inftrees.o trees.o uncompr.o zutil.o  zlibrc.o
gzlib.o:gzlib.c:(.text+0xa4b): undefined reference to `_wopen'
gzlib.o:gzlib.c:(.text+0xa4b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `_wopen'
gzlib.o:gzlib.c:(.text+0xbf9): undefined reference to `_wopen'
gzlib.o:gzlib.c:(.text+0xbf9): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `_wopen'
collect2: error: ld returned 1 exit status
make: *** [win32/Makefile.gcc:96: zlib1.dll] Error 1

Administrator@WIN-J4M9KOMET5D  /c/jenkins/workspace/win64/zlib-1.2.11
$ gcc -dumpmachine
x86_64-pc-msys

Administrator@WIN-J4M9KOMET5D  /c/jenkins/workspace/win64/zlib-1.2.11

I'm using mingw-w64-x86_64-gcc installed via pacman. Any ideas how to fix this?

@noloader

This comment has been minimized.

Copy link

noloader commented Oct 16, 2017

Same problem here... Using latest Cygwin:

Checking for gcc...
Checking for shared library support...
No shared library support; try without defining CC and CFLAGS
Building static library libz.a version 1.2.11 with gcc.
Checking for size_t... Yes.
Checking for off64_t... No.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... No.
gcc -m64 -I. -c -o example.o test/example.c
gcc -m64  -c -o adler32.o adler32.c
gcc -m64  -c -o crc32.o crc32.c
gcc -m64  -c -o deflate.o deflate.c
gcc -m64  -c -o infback.o infback.c
gcc -m64  -c -o inffast.o inffast.c
gcc -m64  -c -o inflate.o inflate.c
gcc -m64  -c -o inftrees.o inftrees.c
gcc -m64  -c -o trees.o trees.c
gcc -m64  -c -o zutil.o zutil.c
gcc -m64  -c -o compress.o compress.c
gcc -m64  -c -o uncompr.o uncompr.c
gcc -m64  -c -o gzclose.o gzclose.c
gcc -m64  -c -o gzlib.o gzlib.c
gcc -m64  -c -o gzread.o gzread.c
gzlib.c: In function ‘gz_open’:
gzlib.c:243:20: warning: implicit declaration of function ‘_wopen’ [-Wimplicit-function-declaration]
         fd == -2 ? _wopen(path, oflag, 0666) :
                    ^~~~~~
gcc -m64  -c -o gzwrite.o gzwrite.c
gcc -m64 -I. -c -o minigzip.o test/minigzip.c
ar rc libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
gcc -m64 -o example.exe example.o -L. libz.a
gcc -m64 -o minigzip.exe minigzip.o -L. libz.a
libz.a(gzlib.o):gzlib.c:(.text+0x3e0): undefined reference to `_wopen'
libz.a(gzlib.o):gzlib.c:(.text+0x3e0): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `_wopen'
collect2: error: ld returned 1 exit status
make: *** [Makefile:289: example.exe] Error 1
make: *** Waiting for unfinished jobs....
libz.a(gzlib.o):gzlib.c:(.text+0x3e0): undefined reference to `_wopen'
libz.a(gzlib.o):gzlib.c:(.text+0x3e0): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `_wopen'
collect2: error: ld returned 1 exit status
make: *** [Makefile:292: minigzip.exe] Error 1
Failed to build zLib

And gzlib.c:

    /* open the file with the appropriate flags (or just use fd) */
    state->fd = fd > -1 ? fd : (
#ifdef WIDECHAR
        fd == -2 ? _wopen(path, oflag, 0666) :
#endif
        open((const char *)path, oflag, 0666));

And gzguts.h:

#if defined(_WIN32) || defined(__CYGWIN__)
#  define WIDECHAR
#endif

According to _open, _wopen on MSDN, it looks like a Microsoft function. Maybe zLib needs to be modified to check for _WINDOWS && ! _CYGWIN.

@noloader

This comment has been minimized.

Copy link

noloader commented Oct 16, 2017

OK, so here is the Stack Overflow question that appears to cover it: Compiling gcc-7-20170212 on Windows 7-64 with cygwin, ==> wopen error.

It got me to this patch for my shell script and things built cleanly:

if [[ "$IS_CYGWIN" -ne "0" ]]; then
    if [[ -f "gzguts.h" ]]; then
        sed -i 's/defined(_WIN32) || defined(__CYGWIN__)/defined(_WIN32)/g' gzguts.h
    fi
fi

I think MinGW is the one that uses Microsoft libraries. Maybe that should be s/defined(_WIN32) || defined(__CYGWIN__)/defined(_WIN32) || defined(__MINGW32__)/g. IIRC, __MINGW32__ is defined for both 32-bit and 64-bit versions of MinGW.

@jeking3

This comment has been minimized.

Copy link

jeking3 commented Nov 23, 2017

I just ran into this issue when I was adding appveyor CI support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment