ZLIB Static Link (1.2.8) on Visual Studio 2012

I cannot, for the love of God, statically link ZLIB libraries. Iโ€™ve been struggling without success for a couple of hours. Well, I followed this tutorial and successfully compiled both zlibstat.lib and zlibwapi.lib for 32 bits. After setting up my project to use the ZLIB folder with libraries (Linker> General> Additional Library Directories) and setting zlibwapi.lib (only) as a dependency (Linker> Input> Additional Dependencies), I got it working , however this is a dynamic link (I need to distribute my application with ZLIB dll). I usually use dynamic binding to Debug and static in Release.

I tried looking for what the hell is zlibstat.lib and what it was used for, if not for static binding, provided the suffix is โ€‹โ€‹"stat".

Is there any preprocessor that should be added to my project, something like ZLIB_STATIC or something, use static ZLIB binding or should I never remove ZLIB_WINAPI from the zlibstat project, as mentioned above? Is a static ZLIB connection impossible (then what is zlibstat.lib for?)?

I'm pretty lost. Any help POSSIBLE is much appreciated.

Edit (additional information):

Errors:

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

Linking:

Unlike the dynamic link (which worked), where I added zlibwapi.lib as a dependency, for the static link that I am trying to reach, I added zlibstat.lib as a dependency instead! No other libraries have been added!

This question may look like this (view).

+5
source share
1 answer

I finally managed to solve my problem. For those who fall into such a problem, they understand how to solve it:

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

The curious thing is that when the application was launched in debug mode (which used dynamic linking), everything succeeded and worked like a charm, without any warnings or, HOWEVER, in the release mode (which used static linking), it crashed.

So, to clarify the situation, the tutorial tells us to remove the ZLIB_WINAPI preprocessor from the zlibstat project , which creates a static lib, while the zlibvc project has ZLIB_WINAPI in the preprocessor . In other words, this means that if we use different links for each configuration (debug / release), we must add the macro ZLIB_WINAPI or not!

Define the ZLIB_WINAPI macro before including "zlib.h" if you use dynamic linking (zlibwapi.lib) and that the zlibvc project remains unchanged (assuming that you followed the tutorial correctly from the link above), and do not define it if you removed ZLIB_WINAPI from the zlibstat project (as our tutorial says)!

One useful macro that I used in 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 are really confused, and I really hope that I was clear enough.

+3
source

Source: https://habr.com/ru/post/1234746/


All Articles