I can't figure out how to interface with the zlib.lib that libpng builds - is it incompatible? [VS 2019, Windows]

David Horman <[email protected]> Sat, 9 Jan 2021 01:42:36 +0000
Newsgroups gmane.comp.graphics.png.devel
Message-ID <[email protected]>
Hi,

I hope this is the right place to ask this, and apologies in advance for 
any incoherence or misunderstandings in my post. As a programmer, my 
knowledge is quite lacking in some fields, such as linking libraries, 
which is what my question is about - I generally just bumble may way 
through online tutorials until it works. So I'm probably overlooking 
something extremely obvious, but lack the knowledge to even know where 
to begin to look.

I'm the author of a small open-source project that incorporates libpng. 
I primarily use Visual Studio on Windows (although my project can also 
be compiled on Linux with gcc and -lpng) and was able to compile libpng 
1.6.37 to a static library from source by downloading it, and zlib, and 
placing them in the same directory.

This generates a pnglib.lib and a zlib.lib in the lpng1637 directory 
structure which my project can successfully link to. I can read and 
write PNGs with no trouble.

Now I want to directly use zlib in my project to compress some data - 
nothing to do with PNGs - but I'm having trouble. I'm following the zlib 
1.2.11 manual, but whenever I try to deflateInit(...) or compress(...) I 
get a return value of Z_STREAM_ERROR - this despite the fact that I'm 
copy and pasting code directly from examples and tutorials. I found a 
zlib example VS project online which directly compiles some zlib source 
code into itself, and the code in question works fine in that project.

I found a couple of examples of people asking about this, on 
StackOverflow and Reddit, but no solutions.

The code in question is:

     z_stream strm;
     strm.zalloc = Z_NULL;
     strm.zfree = Z_NULL;
     strm.opaque = Z_NULL;

     int ret = deflateInit(&strm, -1); // always returns Z_STREAM_ERROR

Does libpng introduce some kind of incompatability into its zlib.lib 
which is stopping me from successfully using it in my project? I 
#include the original zlib.h from zlib 1.2.11.

Thanks in advance,

David



_______________________________________________
png-mng-implement mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/png-mng-implement