Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No zlib.h file in usr/local/include how to get it

so I have been trying to run a C++ program which requires Zlib library on compiling the file it gave an error saying "zlib.h no such file or directory exists" upon looking in usr/local/include i found that the file is not there can i just copy the file to that location or should i Install some thing. i am kinda new to ubuntu so please help

like image 219
rac cool Avatar asked Jun 03 '16 09:06

rac cool


1 Answers

Install zlib with development support by using

sudo apt-get install zlib1g-dev

In case you don't want or need to use the full zlib, it is fairly easy to write wrapper routines which map the zlib functions 1:1 to ordinary file functions which don't support compression and decompression.

//
//  dummy zlib.h
//

#pragma once
#include <stdio.h>

typedef FILE *gzFile;

int gzclose(gzFile file);
gzFile gzdopen(int fd, const char *mode);
gzFile gzopen(const char *path, const char *mode);
int gzread(gzFile file, void *buf, unsigned int len);


//
//  zlibDummy.cpp
//

#include <zlib.h>

int gzclose(gzFile file)
{
    return fclose(file);
}

gzFile gzdopen(int fd, const char *mode)
{
    return _fdopen(fd, mode);
}

gzFile gzopen(const char *path, const char *mode)
{
    return fopen(path, mode);
}

int gzread(gzFile file, void *buf, unsigned int len)
{
    return fread(buf, 1, len, file);
}
like image 59
Axel Kemper Avatar answered Oct 13 '22 01:10

Axel Kemper