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 appeare开发者_C百科d 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.
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.
zlib1.dll needs to be in the path or in the same directory as the executable.
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.
you should copy these files(zconf.h and zlib.h) in the MSVC/include/ folder in qt installation folder
for example this files should be exist: C:\Qt\Qt5.14.2\5.14.2\msvc2017_64\include\QtZlib\zlib.h C:\Qt\Qt5.14.2\5.14.2\msvc2017_64\include\QtZlib\zconf.h
精彩评论