views:

77

answers:

3

I'm trying to port a program that uses zlib to Windows with MSVC. Unfortunately, though, after many hours of trying I can't seem to get anything referencing zlib to run.

Here's a dummy program I'm using to test whether zlib can run:

#include <zlib.h>
#include <stdio.h>

int main(void)
{
    z_stream zst;
    zst.zalloc = Z_NULL;
    zst.zfree = Z_NULL;
    zst.opaque = Z_NULL;
    zst.next_out = Z_NULL;
    zst.next_in = Z_NULL;
    zst.avail_out = 0;

    inflateInit(&zst);

    puts("hello, world!");

    return 0;
}

After installing zlib by copying the contents of the zlib DLL archive found here into their respective GnuWin32 directories (as the setup found here appeared to include an invalid header), I attempted compile the test program with the following:

C:\Documents and Settings\Administrator\My Documents>cl test.c -I"C:\Program Files\GnuWin32\include" "C:\Program Files\GnuWin32\lib\zlib.lib"
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.0 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved

test.c
Microsoft (R) Incremental Linker Version 9.0030729.01
Copyright (C) Microsoft Corporation. All rights reserved.

/out:test.exe
test.obj
"C:\Program Files\GnuWin32\lib/zlib.lib"

Then, when I attempt to run test.exe, I get an error dialog stating:

This application has failed to start because zlib1.dll was not found. Re-installing the application may fix this problem.

Any help would be very much appreciated.

A: 

zlib1.dll needs to be in the path or in the same directory as the executable.

jdigital
A: 

It sounds like you have zlib1.dll in the GnuWin32 directory? The easiest way to get zlib1.dll recognized will probably be to copy it into the same directory as test.exe. You can also download a free tool called Dependecy Walker to get a better idea of why zlib1.dll can't be found.

Ben Karel
A: 

You should read the DLL_FAQ.txt file included with the ZLIB distribution, in the Win32 directory. It explains why they use ZLIB1.dll instead of ZLIB.dll, why the change was made, what the differences are, and gives you insight into the choices you can make.

Cheeso