78

I am trying to compile software on Blue Gene Q using IBM XL compilers and I got this error message:

"iostreams/zlib.cpp", line 19.10: 1540-0836 (S) The #include file "zlib.h" is not found.
make[3]: *** [zlib.o] Error 1

I have installed a new version of zlib and updated LD_LIBRARY_PATH with $HOME/zlib/include

Am I missing something?

Machavity
  • 30,841
  • 27
  • 92
  • 100
didymos
  • 1,191
  • 3
  • 10
  • 13

5 Answers5

197

You are missing zlib.h header file, on Linux install it via:

sudo apt-get install libz-dev

As a matter of fact, the module presents as zlib1g-dev in the apt repo, so this is the up-to-date call (Feb 2019):

sudo apt install zlib1g-dev

On Fedora: sudo dnf install zlib-devel (in older versions: sudo dnf install libz-devel).

This will provide the development support files for a library implementing the deflate compression method found in gzip and PKZIP.

If you've already zlib library, make sure you're compiling your code sources with -lz. See: How to fix undefined references to inflate/deflate functions?.

Berta Dénes
  • 93
  • 3
  • 11
kenorb
  • 155,785
  • 88
  • 678
  • 743
  • 4
    I had the same issue with fedora 25. Solution is `sudo dnf install libz-devel` – Krzysztof Czeronko Mar 08 '17 at 21:54
  • 3
    with fedora 28, I had to `sudo dnf install zlib-devel` instead – Alex Gyoshev Jun 21 '18 at 05:59
  • 1
    Had the same issue on Debian while trying to install Backup from ruby `gem`. Had `fatal error: zlib.h: No such file or directory`in `mkmf.log` and `zlib is missing; necessary for building libxml2` in console. – Mtxz Jan 20 '19 at 16:03
22

You have installed the library in a non-standard location ($HOME/zlib/). That means the compiler will not know where your header files are and you need to tell the compiler that.

You can add a path to the list that the compiler uses to search for header files by using the -I (upper-case i) option.

Also note that the LD_LIBRARY_PATH is for the run-time linker and loader, and is searched for dynamic libraries when attempting to run an application. To add a path for the build-time linker use the -L option.

All-together the command line should look like

$ c++ -I$HOME/zlib/include some_file.cpp -L$HOME/zlib/lib -lz
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • 9
    @SmallChess Considering that the OP says "I have ***installed*** a new version of zlib..." (emphasis mine) and marked my answer as accepted, perhaps you can elaborate on why? Just because an answer have more votes doesn't mean it's automatically correct. – Some programmer dude Aug 07 '17 at 07:22
  • 4
    I feel like most people that up voted kernob's answer, didn't fully read the question. – searchengine27 Jan 11 '18 at 15:58
  • 1
    The question says zlib has been installed. But makes no mention of the dev zlib package. Installing zlib binary (in most distros) by itself does not install zlib.h. However, both answers completely answer this question. Most people are probably not developing software with zlib. But rather installing software by compiling. Hence, the higher votes below. And advanced answer above. – TamusJRoyce Jun 02 '19 at 03:34
0

I also had the same problem. Then I installed the zlib, still the problem remained the same. Then I added the following lines in my .bashrc and it worked. You should replace the path with your zlib installation path. (I didn't have root privileges).

export PATH =$PATH:$HOME/Softwares/library/Zlib/zlib-1.2.11/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/Softwares/library/Zlib/zlib-1.2.11/lib/
export LIBRARY_PATH=$LIBRARY_PATH:$HOME/Softwares/library/Zlib/zlib-1.2.11/lib/
export C_INCLUDE_PATH=$HOME/Softwares/library/Zlib/zlib-1.2.11/include/
export CPLUS_INCLUDE_PATH=$HOME/Softwares/library/Zlib/zlib-1.2.11/include/
export PKG_CONFIG_PATH=$HOME/Softwares/library/Zlib/zlib-1.2.11/lib/pkgconfig
Bhanuday Sharma
  • 323
  • 3
  • 10
0

In openSUSE 19.2 installing the patterns-hpc-development_node package fixed this issue for me.

Peri
  • 574
  • 1
  • 3
  • 19
Onkar
  • 1
0

Maybe you can download zlib.h from https://dev.w3.org/Amaya/libpng/zlib/zlib.h, and put it in the directory to solve the problem.