Visual Studio 2012 上的静态 ZLIB (1.2.8) 链接 [英] Static ZLIB (1.2.8) linking on Visual Studio 2012

查看:47
本文介绍了Visual Studio 2012 上的静态 ZLIB (1.2.8) 链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看在上帝的份上,我不能静态链接 ZLIB 库.我已经挣扎了几个小时,但没有成功.好吧,我已经按照这个教程 并成功编译了两者zlibstat.lib 和 zlibwapi.lib 为 32 位.将我的项目设置为使用带有库的 ZLIB 文件夹(链接器 > 常规 > 附加库目录)并将 zlibwapi.lib(仅)设置为依赖项(链接器 > 输入 > 附加依赖项)后,我让它工作,但是,这是一个动态链接(我需要使用 ZLIB dll 分发我的应用程序).我通常在调试时使用动态链接,在发布时使用静态链接.

I can't, for the love of God, to static link the ZLIB libs. I have been struggling for a couple hours now with no success. Well, I have followed this tutorial and successfuly compiled both zlibstat.lib and zlibwapi.lib for 32 bits. After setting up my project to use the ZLIB folder with the libraries (Linker > General > Additional Library Directories) and setting zlibwapi.lib (only) as an dependency (Linker > Input > Additional Dependencies) I got it to work, however, that was a dynamic link (I need to distribute my application with the ZLIB dll). I usually use dynamic linking on Debug and static on Release.

我已经尝试寻找 zlibstat.lib 到底是什么以及它用于什么,如果不是静态链接,假设stat"后缀.

I have tried looking for what the hell is the zlibstat.lib and whats it used for, if not for static linking, assuming the "stat" suffix.

是否有任何预处理器要添加到我的项目中,例如 ZLIB_STATIC 之类的东西,以使用 ZLIB 的静态链接,或者我是否应该从未从 zlibstat 项目中删除 ZLIB_WINAPI,就像上面的链接告诉我的那样?是否无法静态链接 ZLIB(那么,zlibstat.lib 是什么?)?

Are there any preprocessor to be added into my project, something like ZLIB_STATIC or something, to use static linking of ZLIB or should I have never removed the ZLIB_WINAPI from the zlibstat project, just like the above link told me to do? Is it impossible to static link ZLIB (then, whats zlibstat.lib for?)?

我很迷茫.非常感谢任何帮助.

I am pretty lost. Any help is GREATLY appreciated.

编辑(额外信息):

错误:

error LNK2001: unresolved external symbol _inflateInit_@12
error LNK2001: unresolved external symbol _inflate@8
error LNK2001: unresolved external symbol _inflateEnd@4

链接:

与我添加 zlibwapi.lib 作为依赖项的动态链接(有效)不同,对于我试图实现的静态链接,我添加了 zlibstat.lib 作为依赖项!没有添加其他库!

Unlike the dynamic link (that worked) where I added zlibwapi.lib as a dependency, for the static linking I'm trying to achieve I added zlibstat.lib as a dependency instead! No other libs were added!

这个问题可能看起来像这个(有点).

This question might look like this (kind of).

推荐答案

我终于设法解决了我的问题.对于那些最终遇到此类问题的人,以下是解决方法:

I have finally managed to solve my problem. For those that end up in such a problem, heres how to solve it:

如果您按照我的第一篇文章中的教程进行操作,您就会从 zlibstat 项目的预处理器中删除 ZLIB_WINAPI.但是,在使用 ZLIB 设置我自己的项目(设置 ZLIB 依赖项路径、LIB 依赖项库等)后,我不小心"在头文件中包含/定义了该死的 ZLIB_WINAPI 宏,我正在使用 ZLIB,就在包含zlib.h"之前.

If you followed the tutorial in my first post, you would have removed ZLIB_WINAPI from the zlibstat project's Preprocessor. However, after setting up my own project (setting ZLIB dependencies path, LIB dependencies libraries etc) that uses ZLIB, I 'accidently' included/defined the damned ZLIB_WINAPI macro in the header file I'm using ZLIB, right before including "zlib.h".

对此的一个奇怪之处在于,当在调试模式(使用动态链接)下启动应用程序时,一切都成功并像魅力一样工作,没有任何警告或无论如何,在发布模式(使用静态链接),它崩溃了.

One curious thing about this is that when launching the app on debug mode (which was using dynamic linking), everything succeeded and worked like a charm, without any warnings or whatsoever, HOWEVER, on release mode (which was using the static linking), it crashed.

因此,为了解决问题,教程告诉我们从 zlibstat 项目中移除 ZLIB_WINAPI 预处理器,它生成静态库,而 zlibvc项目在其预处理器中具有 ZLIB_WINAPI.换句话说,这意味着如果我们为每个配置(调试/发布)使用不同的链接,我们必须添加或不添加 ZLIB_WINAPI 宏!

So, to clear things up, the tutorial tells us to remove the ZLIB_WINAPI preprocessor from the zlibstat project, which produces the static lib, whilst the zlibvc project has the ZLIB_WINAPI in its preprocessor. In other words, that means that if we're using different linkings for each configuration (debug/release), we have to add the ZLIB_WINAPI macro or not!

如果您使用动态链接 (zlibwapi.lib) 并且 zlibvc 项目保持不变(假设您正确地遵循了上面链接中的教程),如果您从 zlibstat 项目中删除了 ZLIB_WINAPI(就像教程告诉我们的那样),则不要定义它!

Define the ZLIB_WINAPI macro before including "zlib.h" if youre using dynamic linking (zlibwapi.lib) and that the zlibvc project remains unmodified (assuming you correctly followed the tutorial from the link above) and do not define it if you removed ZLIB_WINAPI from the zlibstat project (like the tutorial tell us to)!

我在自己的项目中使用的一个有用的宏如下:

One helpful macro I used on my own project is as follows:

// Since we used dynamic linking for debug, we have to define the ZLIB_WINAPI
#if defined(_WIN32) && defined(_DEBUG)
    #define ZLIB_WINAPI
#endif
#include <zlib.h>

事情变得非常混乱,我真的希望我足够清楚.

Things got really confusing and I really hope I was clear enough.

这篇关于Visual Studio 2012 上的静态 ZLIB (1.2.8) 链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆