无法在 Windows 上使用 zlib 依赖项进行编译?
我正在尝试使用 MSVC 将使用 zlib 的程序移植到 Windows。但不幸的是,经过几个小时的尝试,我似乎无法运行任何引用 zlib 的内容。
这是我用来测试 zlib 是否可以运行的虚拟程序:
#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;
}
通过复制 zlib DLL 存档的内容安装 zlib 后发现 here 进入各自的 GnuWin32 目录(因为设置发现 here 出现包含无效的标头),我尝试使用以下内容编译测试程序:
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"
然后,当我尝试运行 test.exe 时,我收到一个错误对话框,指出:
该应用程序无法启动 因为没有找到zlib1.dll。 重新安装应用程序可能会修复 这个问题。
任何帮助将非常感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
听起来 GnuWin32 目录中有
zlib1.dll
?识别zlib1.dll
的最简单方法可能是将其复制到与test.exe
相同的目录中。您还可以下载一个名为 Dependency Walker 的免费工具,以更好地了解原因找不到zlib1.dll
。It sounds like you have
zlib1.dll
in the GnuWin32 directory? The easiest way to getzlib1.dll
recognized will probably be to copy it into the same directory astest.exe
. You can also download a free tool called Dependecy Walker to get a better idea of whyzlib1.dll
can't be found.zlib1.dll 需要位于可执行文件的路径或同一目录中。
zlib1.dll needs to be in the path or in the same directory as the executable.
您应该阅读 ZLIB 发行版中包含的 Win32 目录中的 DLL_FAQ.txt 文件。它解释了为什么他们使用 ZLIB1.dll 而不是 ZLIB.dll、为什么进行更改、差异是什么,并让您深入了解可以做出的选择。
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.
您应该将这些文件(zconf.h 和 zlib.h)复制到 qt 安装文件夹中的 MSVC/include/ 文件夹中,
例如该文件应该存在:
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
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