Fixing the "Could Not Find Zlib (Missing: ZLIB_Library ZLIB_Include_Dir)" Error

Summary

Are you having trouble trying to build CMake with ZLib options? If so, this document should provide an explanation and instructions to correct this error.

Affected Development Environment

  • Platform: Linux, Mac, and/or Windows
  • Compiler/builder: CMake

Overview

ZLib is an open-source library used for data compression and decompression. This error occurs because CMake does not recognize the ZLib library and include directories when trying to build the project.

Steps to Fix

In order to fix this error, make sure you have downloaded and included the library and headers of ZLib in your environment.

  • Download the latest version of ZLib from here.
  • Follow the instructions included in the README file to install the library.
  • On Linux and Mac systems, the library should be installed in /usr/lib and the headers should be installed in /usr/include.
  • On Windows systems, the library (zlib1.dll) should be copied into CMake's bin directory.
  • Once the library is installed, using -D compile options provide the library and include directories to the CMake build definition.
  • -DZLIB_LIBRARY:FILEPATH=<path to the library> -DZLIB_INCLUDE_DIR:PATH=<path to the headers>

You should now be able to build the project with CMake without any errors.

FAQ

  1. What is ZLib used for?
  • ZLib is an open-source library used for data compression and decompression.
  1. Where can I download the library?
  • You can download the latest version of ZLib from here.
  1. What are the -D compile options to provide the library and include directories to CMake build definition?
  • -DZLIB_LIBRARY:FILEPATH=<path to the library> -DZLIB_INCLUDE_DIR:PATH=<path to the headers>
  1. Where can I find instructions for installing the library on my system?
  • The instructions for installation can be found in the README file included with the download.
  1. On what platforms is ZLib supported?
  • ZLib is supported on Linux, Mac, and Windows systems.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Lxadm.com.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.