无法在 Windows 上使用 zlib 依赖项进行编译?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1919356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:36:29  来源:igfitidea点击:

Can't compile with zlib dependency on Windows?

windowsdllvisual-c++zlib

提问by Sam

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.

我正在尝试使用 MSVC 将使用 zlib 的程序移植到 Windows。不幸的是,经过数小时的尝试,我似乎无法获得任何引用 zlib 的内容来运行。

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

这是我用来测试 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;
}

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

通过将此处找到的 zlib DLL 存档的内容复制到各自的 GnuWin32 目录中来安装 zlib 后(因为此处找到的设置似乎包含无效的头文件),我尝试使用以下内容编译测试程序:

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:

然后,当我尝试运行 test.exe 时,我收到一个错误对话框,说明:

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

此应用程序无法启动,因为未找到 zlib1.dll。重新安装应用程序可能会解决此问题。

Any help would be very much appreciated.

任何帮助将不胜感激。

采纳答案by Ben Karel

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

听起来您zlib1.dll在 GnuWin32 目录中有?获得zlib1.dll认可的最简单方法可能是将其复制到与test.exe. 您还可以下载一个名为Dependecy Walker的免费工具,以更好地了解为什么zlib1.dll找不到。

回答by jdigital

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

zlib1.dll 需要与可执行文件位于路径或同一目录中。

回答by Cheeso

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.

您应该阅读 Win32 目录中 ZLIB 分发包中包含的 DLL_FAQ.txt 文件。它解释了为什么他们使用 ZLIB1.dll 而不是 ZLIB.dll,为什么要进行更改,差异是什么,并让您深入了解您可以做出的选择。