ZLib To Extract A Zip

I am learning C++ and want to use zlib to extract a .zip file. I am lost on how to do this and would love it if someone could provide some guidance for me :)
Have you even read the zlib homepage?
https://www.zlib.net/zlib_how.html
Yes - I have seen it and looked at it. And I even saw the https://github.com/madler/zlib/blob/master/contrib/minizip/miniunz.c

but I am not sure on how to use this...
Yeah, probably better if you start with something actually written in C++.

Not some C code written in the pre-ANSI style to cater for all manner of backward compilers.
I disagree somewhat. If they provided a working (even if crude) example, and it either does what you need or can be shoehorned into doing what you need with a tiny bit of effort, just use that. Rewriting it just to change the language or modernize it seems like a waste of time?
It sounds like miketheknight2016 just has never tried to install a library before. The issue isn't the source code of the example written (I mean, maybe that's part of the issue, but I don't think it's the root cause here). Also just to be clear, once that program is built, the usage of it looks like this:
Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir]

The [arguments] are optional.
Try it like
miniunz file_to_unzip.zip


It would help if you would tell us what platform you are trying to install zlib on. Ubuntu? Window? Some other Linux distro?

Well, regardless, see these links:
Ubuntu - https://askubuntu.com/a/508937
Windows MinGW - https://stackoverflow.com/questions/4163170/using-zlib-under-windows-mingw

The MinGW distro I have on Windows already came with zlib installed, by the way.
https://nuwen.net/mingw.html

You link to libz by adding the -lz option to your compiler.
Last edited on
jonnin wrote:
Rewriting it just to change the language or modernize it seems like a waste of time?

That depends on whether you want it to be able to compile in C++ or not.
@Ganado - I am on OSX - and have a .zip called Test.zip in my Downloads folder. How would I extract that?

MiniGW is installed on my distro as it is a part of devkitpro and I have that installed.
Last edited on
Mostly, I would suggest downloading the ZIP program ported to your OS.

Unless you ACTUALLY want to write your own code.
salem c + 1
@Salem C - I have it installed for my OS - I just lack the C++ skills on how to use it.
If you're on OS X, you don't need MinGW, that's a Windows thing.
I'm not too familiar with OSX... if you have g++ installed, try something like
g++ miniunz.c -lz -o miniunz
Last edited on
@Ganado -
does it matter what dir I'm in from terminal when I run this command? I tried it and got these errors:
MacBook-Pro:~ owner$ g++ miniunz.c lz -o miniunz
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: error: no such file or directory: 'miniunz.c'
clang: error: no such file or directory: 'lz'
clang: error: no input files

and yes I have G++ installed.
I didn't do enough research before making that post. I thought that file was standalone source code that just needed to be linked with libz. It's actually part of a whole directory of files.

You need to download the entire directory that that Github file is in.
...I tried building the example myself, but I run into a bunch of "multiple definition" errors when I try to build with gcc, and even more errors when I build with g++. I don't think I'm going to try to figure out what exactly is wrong, but here was my command (on Windows):

gcc *.c -IC:\MinGW\include -lz -o miniunz

Edit: I got it to compile.
1. Download the entire minizip directory from GitHub to your computer.
2. Then move (or delete) the "minizip.c" file to another place so it doesn't interfere.
3. Then, run the command posted above (but change your -I directory so that it goes to the correct directory that zlib.h is in)

If you're still running into errors, I'm not sure I'll be able to help more.

Also note it's -lz, not lz.
Last edited on
I'm confused.
http://magma.maths.usyd.edu.au/magma/faq/extract

Mac OS X users

Mac OS X will unpack a .tar.gz, .tar, or .zip file automatically when you double-click on its icon. (Note that it may be necessary to unpack some files twice.)


What exactly is your issue again?


Your suggesting that he simply download a program that extracts ZIPs for him. That's fine, but in the OP he stated that he wanted to use zlib (presumably with C++, since this is a C++ forum). That means that if his compiler doesn't already have zlib installed, he needs to build zlib, and then link to it to successfully compile the example code.

On Linux or msys2, it's usually as easy as typing in "./configure [options]" and then "make" and "make install".
On Mac OS X, I have no idea, but it might already be installed as part of his compiler.

The zlib site claims that zlib is already installed on Macs by default
https://www.zlib.net/
> zlib for macOS (Mac OS X): zlib is already included as part of macOS
So this means that OP just needs to link to where the library file is, and find where the header file is. I think.
Last edited on
Topic archived. No new replies allowed.