31

Or any include directory/library.

I use cmake gui tool so I run it and usually the gui will highlight the include or library it can't find and let you open a open dialog to set the path however it doesn't do that for this cmake cofig it tell you in red text in the output in the gui tool, so,

CMake Error at C:/Program Files/CMake/share/cmake-3.0/Modules/FindPackageHandleStandardArgs.cmake:136 (message):
  Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.0/Modules/FindPackageHandleStandardArgs.cmake:343 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files/CMake/share/cmake-3.0/Modules/FindZLIB.cmake:101 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  src/CMakeLists.txt:7 (find_package)

So still using the gui how do I point cmake to the zlib include dir?

graham
  • 411
  • 1
  • 4
  • 5

6 Answers6

26

Quick solution: apt-get install zlib1g-dev

radu
  • 357
  • 3
  • 2
19

I'll first assume you have ZLib installed somewhere, and my guess is that it's in a non-standard location since CMake find it. If that's true, you can set the location in CMake-gui. You'll need to first click the 'Advanced' checkbox near the top, because the FindZLIB.cmake file has the following line "mark_as_advanced(ZLIB_LIBRARY ZLIB_INCLUDE_DIR)".

Now you should be able to see the ZLIB_LIBRARY ZLIB_INCLUDE_DIR options and set the correct path.

StAlphonzo
  • 736
  • 5
  • 14
  • 1
    How to pass it without the GUI? (what does the GUI do actually - where is this stored? Or does it just work for generating build via GUI, and the options are passed to `cmake` command? – Tomasz Gandor Sep 08 '16 at 13:30
  • 5
    If I understand the question correctly, if you are just calling `cmake src_dir`, you can a a list of arguments with a -D prefix. In this case, it would be `cmake -DZLIB_LIBRARY=/lib/path -DZLIB_INCLUDE_DIR=/include/path src_dir` – StAlphonzo Sep 09 '16 at 13:26
  • I do not understand. I entered source folder path, build folder path, then clicked 'Advanced'... and nothing happend, the main listview is empty. Where exactly I should be able to see ZLIB_LIBRARY ZLIB_INCLUDE_DIR options? – HiFile.app - best file manager Mar 21 '19 at 09:33
  • 1
    Those variables will only show up if one of your CMakeLists.txt files calls `FindPackage(ZLIB)`. Otherwise, your build won't know it needs zlib until you get a link error. The FindPackage call is also the only way to automatically have the library name set for you correctly. With it, you can use `${ZLIB_LIBRARY}` rather than just hard-coding `z` in your target_link_libraries call. – StAlphonzo Apr 15 '19 at 11:55
  • 只有ZLIB_INCLUDE_DIR 需要 Advanced选项。 – Crawl.W Aug 28 '20 at 01:26
6

For future googlers, according to the docs:

An includer may set ZLIB_ROOT to a zlib installation root to tell this module where to look.

Elhanan Ilani
  • 174
  • 2
  • 3
4

When you make and build zlib library, you need zlib.lib static library and zlib.h and zconf.h header files to make minizip libray.

So, after building zlib you have the following that are need for minizip :

  • zlib.lib in Release or Debug folder.
  • zlib.h and zconf.h header files in zlib root directory.

Now set DZLIB_LIBRARY and DZLIB_INCLUDE_DIR like this :

cmake -G "Visual Studio 14 2015" -A Win32 -DZLIB_LIBRARY="zlib-master\Release"  -DZLIB_INCLUDE_DIR="zlib-master"

This solution does worked for me when i need minizip library and hope this could help you.

2

To add to Elhanan Ilani's answer (for any novices, like myself), this should be declared near the top of the CMakeLists.txt file. For example:

set(ZLIB_ROOT /home/foo/zlib-1.2.11/)
set(CURL_ROOT /home/foo/anaconda3/)
Josh
  • 41
  • 2
-1

in my case, set ZLIB_ROOT, ZLIB_LIBRARY

c:\zlib - include
        - lib
sailfish009
  • 2,561
  • 1
  • 24
  • 31