Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using zlib under windows mingw

I can't seem to get zlib to do anything on mingw under windows.

I downloaded zlib @ http://sourceforge.net/projects/mingw/files_beta/MinGW/zlib/zlib-1.2.3-1-mingw32/ and put the header and lib files in the right place.

Simple code like:

#include <stdlib.h>
#include <stdio.h>

#include "zlib.h"

int main(int argc, char *argv[])
{
    long a;
    char buffer[1024];
    a = 1024;
    compress(buffer,&a,"testing",7);
    return 0;
}

compiled:

gcc test.c -lzlib -Wall -o test.exe

Compiles fine. However the exe crashes at the compress function. Any ideas?

like image 660
myforwik Avatar asked Nov 12 '10 09:11

myforwik


1 Answers

I recommend using MSYS2 for this kind of thing. These instructions assume you want to compile a 64-bit program, but they can easily be modified for 32-bit.

After installing MSYS2, run the "MinGW-w64 Win64 Shell" shortcut in your Start Menu. Install the 64-bit toolchain by running:

pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-zlib

Then compile your code by running something like this:

gcc test.c -lz -o test

I did not check your code carefully, but I was able to run your code without any crashing, so your code might be OK. Your code also gives no output so it's hard to tell if it really worked.

like image 59
David Grayson Avatar answered Sep 22 '22 15:09

David Grayson