Installing Zlib in Linux Server

Installing ZLIB in Linux Server

Ok, if you are using Debian, you should do:

su

to become root

apt-get update

to refresh the package lists, then

apt-cache search zlib

to check the relevant packages in the lists you have just updated, then

apt-get install <whatever_package_you_found_earlier>

I suggest using regular expression as search strings for apt-cache, since they are more accurate, as in

apt-cache search ^zlib

to return only package names starting with zlib

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

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);
}

How to detect whether zlib is available and whether ZIP_DEFLATED is available?

  • On Ubuntu if you install Python 3 using apt, e.g. sudo apt install python3.8, zlib will be installed as a dependency.
  • Another way is to install Python 3 from source code. In this case, you need to install all prerequisites, including zlib1g-dev, (and this action is sometimes forgotten to do)
    and then compile and install python as sudo make install. Full instructions here
  • Yes, if zlib is not available import zlib will raise exception, such as
>>> import zlib 
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'zlib

There are examples of code like this in the Python standard
library. e.g. in zipfile.py:

try:
import zlib # We may need its compression method
crc32 = zlib.crc32
except ImportError:
zlib = None
crc32 = binascii.crc32

Git installation RHEL Linux failing with warning: zlib.h: No such file or directory

Solved it by wget zlib.net/zlib-1.2.8.tar.gz and installed the same



Related Topics



Leave a reply



Submit