Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zlib] find_package(zlib) cannot locate correctly installed library files #39099

Closed
petrmanek opened this issue Jun 3, 2024 · 10 comments
Closed

Comments

@petrmanek
Copy link

petrmanek commented Jun 3, 2024

Describe the bug
When configuring a CMake project that depends on zlib, the find_package() call fails even if the port is installed.

Environment

  • OS: Windows 11, latest version as of writing
  • CMake: 3.28.1
  • Compiler: MSVC 19.38.33134.0

To Reproduce
Steps to reproduce the behavior:

  1. ./vcpkg install zlib
  2. Create a simple "hello world" C++ program managed with CMake.
  3. Introduce a library dependency on zlib by using the find_package(zlib REQUIRED) directive in CMakeLists.txt
  4. Attempt to configure the project with CMake and vcpkg's toolchain file.

Expected behavior
CMake successfully configures the project, leaving it ready to build.

Failure logs

CMake Error at C:/vcpkg/installed/x64-windows/share/zlib/vcpkg-cmake-wrapper.cmake:5 (message):
  Broken installation of vcpkg port zlib
Call Stack (most recent call first):
  C:/vcpkg/scripts/buildsystems/vcpkg.cmake:797 (include)
  lib/quazip/CMakeLists.txt:127 (find_package)
-- Configuring incomplete, errors occurred!

Additional context
If I enable debug logging using CMAKE_FIND_DEBUG_MODE=TRUE just before my call to find_package(zlib), I see the following output:

CMake Debug Log at C:/vcpkg/installed/x64-windows/share/zlib/vcpkg-cmake-wrapper.cmake:1 (find_path):
  find_path called with the following settings:
    VAR: ZLIB_INCLUDE_DIR
    NAMES: "zlib.h"
    Documentation: Path to a file.
    Framework
      Only Search Frameworks: 0
      Search Frameworks Last: 1
      Search Frameworks First: 0
    AppBundle
      Only Search AppBundle: 0
      Search AppBundle Last: 1
      Search AppBundle First: 0
    NO_DEFAULT_PATH Enabled
  find_path considered the following locations:
  The item was found at
    C:/vcpkg/installed/x64-windows/include/zlib.h
Call Stack (most recent call first):
  C:/vcpkg/scripts/buildsystems/vcpkg.cmake:797 (include)
  lib/quazip/CMakeLists.txt:127 (find_package)
CMake Debug Log at C:/vcpkg/installed/x64-windows/share/zlib/vcpkg-cmake-wrapper.cmake:2 (find_library):
  find_library called with the following settings:
    VAR: ZLIB_LIBRARY_RELEASE
    NAMES: "zlib"
           "z"
    Documentation: Path to a library.
    Framework
      Only Search Frameworks: 0
      Search Frameworks Last: 1
      Search Frameworks First: 0
    AppBundle
      Only Search AppBundle: 0
      Search AppBundle Last: 1
      Search AppBundle First: 0
    NO_DEFAULT_PATH Enabled
  find_library considered the following locations:
    C:/vcpkg/installed/x64-windows/lib/libzlib(\.lib|\.dll)
    C:/vcpkg/installed/x64-windows/debug/vcpkg/installed/x64-windows/lib/libzlib(\.lib|\.dll)
    C:/vcpkg/installed/x64-windows/lib/libzlib(\.lib|\.dll)
    C:/vcpkg/installed/x64-windows/lib/libz(\.lib|\.dll)
    C:/vcpkg/installed/x64-windows/debug/vcpkg/installed/x64-windows/lib/libz(\.lib|\.dll)
    C:/vcpkg/installed/x64-windows/lib/libz(\.lib|\.dll)
  The item was not found.
Call Stack (most recent call first):
  C:/vcpkg/scripts/buildsystems/vcpkg.cmake:797 (include)
  lib/quazip/CMakeLists.txt:127 (find_package)
CMake Debug Log at C:/vcpkg/installed/x64-windows/share/zlib/vcpkg-cmake-wrapper.cmake:3 (find_library):
  find_library called with the following settings:
    VAR: ZLIB_LIBRARY_DEBUG
    NAMES: "zlibd"
           "z"
    Documentation: Path to a library.
    Framework
      Only Search Frameworks: 0
      Search Frameworks Last: 1
      Search Frameworks First: 0
    AppBundle
      Only Search AppBundle: 0
      Search AppBundle Last: 1
      Search AppBundle First: 0
    NO_DEFAULT_PATH Enabled
  find_library considered the following locations:
    C:/vcpkg/installed/x64-windows/debug/lib/libzlibd(\.lib|\.dll)
    C:/vcpkg/installed/x64-windows/debug/lib/libzlibd(\.lib|\.dll)
    C:/vcpkg/installed/x64-windows/debug/lib/libzlibd(\.lib|\.dll)
    C:/vcpkg/installed/x64-windows/debug/lib/libz(\.lib|\.dll)
    C:/vcpkg/installed/x64-windows/debug/lib/libz(\.lib|\.dll)
    C:/vcpkg/installed/x64-windows/debug/lib/libz(\.lib|\.dll)
  The item was not found.
Call Stack (most recent call first):
  C:/vcpkg/scripts/buildsystems/vcpkg.cmake:797 (include)
  lib/quazip/CMakeLists.txt:127 (find_package)
CMake Error at C:/vcpkg/installed/x64-windows/share/zlib/vcpkg-cmake-wrapper.cmake:5 (message):
  Broken installation of vcpkg port zlib
Call Stack (most recent call first):
  C:/vcpkg/scripts/buildsystems/vcpkg.cmake:797 (include)
  lib/quazip/CMakeLists.txt:127 (find_package)

Using Explorer I can confirm that the following files clearly exist on my system:

  • C:/vcpkg/installed/x64-windows/lib/zlib.lib
  • C:/vcpkg/installed/x64-windows/bin/zlib1.dll
  • C:/vcpkg/installed/x64-windows/debug/lib/zlibd.lib
  • C:/vcpkg/installed/x64-windows/debug/bin/zlibd1.dll

This seems to me like the 'lib' prefix is incorrectly applied inside vcpkg cmake module for zlib.

@petrmanek
Copy link
Author

A quick update: I confirmed that the following variables are configured to empty strings (as they should be on Windows) at the time when find_package(zlib) is called:

  • CMAKE_IMPORT_LIBRARY_PREFIX
  • CMAKE_SHARED_LIBRARY_PREFIX
  • CMAKE_STATIC_LIBRARY_PREFIX

@Neumann-A
Copy link
Contributor

IT IS: find_package(ZLIB REQUIRED)

This seems to me like the 'lib' prefix is incorrectly applied inside vcpkg cmake module for zlib.

give a --trace-expand log if that doesn't fix it

@petrmanek
Copy link
Author

IT IS: find_package(ZLIB REQUIRED)

My bad, I typed too fast. Yes, I am aware of that. Just for context: my project does not depend on zlib directly, instead it includes another package (QuaZip) that depends on zlib. I can confirm that QuaZip uses the correct capitalization.

I will provide a --trace-expand log in a moment.

@petrmanek
Copy link
Author

@Neumann-A Here you go: 41835.log (11 MB)

@Neumann-A
Copy link
Contributor

C:/root_v6.26.10/cmake/ROOTConfig.cmake(120):  if(MSVC )
C:/root_v6.26.10/cmake/ROOTConfig.cmake(121):  set(CMAKE_FIND_LIBRARY_PREFIXES lib )
C:/root_v6.26.10/cmake/ROOTConfig.cmake(122):  set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll )

@petrmanek
Copy link
Author

Lol, you beat me to it by a second!

@petrmanek
Copy link
Author

It seems that simply having a dependency on the ROOT framework seems to mess up CMAKE_FIND_LIBRARY_PREFIXES, and zlib is an innocent casualty.

@petrmanek
Copy link
Author

Since I am using a little bit outdated version of ROOT (6.26), I will confirm that this behavior is present in the latest version (6.32) as well, and file a bug report upstream if need be. I suppose that this is not a vcpkg problem after all.

Thanks for a quick exchange, I am closing this as resolved.

@Neumann-A
Copy link
Contributor

Feel free to use/update https://github.com/Neumann-A/my-vcpkg-ports/tree/master/root
However debug builds of root are buggy / not working on windows.

@petrmanek
Copy link
Author

@Neumann-A Thanks, I will check it out!

In the meantime, I have confirmed that this behavior is indeed present in ROOT 6.32. I will file a bug upstream in a moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants