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 :)
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:
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
@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
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.
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.)
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.