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

[question] Error "Library 'zlib' not found in package." during first tutorial #23330

Closed
1 task done
TheWirv opened this issue Apr 1, 2024 · 6 comments
Closed
1 task done

Comments

@TheWirv
Copy link

TheWirv commented Apr 1, 2024

What is your question?

Hi, I would like to start using conan, but I already struggle with the first tutorial. I had some issues initially because I am using the MSYS64 clang64 toolchain on Windows, but I have resolved those now, and can at least get the conan install working, after having tweaked my profile and global.conf.

However, now I am running into a new problem when trying to build:

CMake Error at build/cmakedeps_macros.cmake:67 (message):
  Library 'zlib' not found in package.

I have already looked at the two issues conan-io/conan#13963 and conan-io/conan#15473, but unfortunately, they weren't of much help, as they also had slightly different errors than mine.

I have also tried @memsharded's comment conan-io/conan#13963 (comment), but that yielded the exact same result.

I am on Windows 11 and am using the following tools:

  • Conan v2.2.2 (installed via pip)
  • CMake v3.29.0
  • Ninja v1.11.1
  • Clang v18.1.2 (Target: x86_64-w64-windows-gnu; Thread model: posix)
  • PowerShell v7.4.1 in Windows Terminal

I am trying to finish the first tutorial, and haven't changed any of the files in the examples2/.../simple_cmake_project repo after having cloned it. I am also using presets, but I have tried it using the "manual command" with -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" as well -- without success.

Here is the output of my command line:

Transcript
=> conan install . --output-folder=build --build=missing

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=20
compiler.libcxx=libc++
compiler.version=18
os=Windows
[conf]
tools.build:compiler_executables={'c': 'C:/msys64/clang64/bin/clang.exe', 'cpp': 'C:/msys64/clang64/bin/clang++.exe'}
tools.cmake.cmaketoolchain:generator=Ninja
tools.env.virtualenv:powershell=True
tools.microsoft.msbuild:installation_path=""
[buildenv]
PATH+=(path)C:/msys64/clang64/bin
[runenv]
PATH+=(path)C:/msys64/clang64/bin

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=20
compiler.libcxx=libc++
compiler.version=18
os=Windows
[conf]
tools.build:compiler_executables={'c': 'C:/msys64/clang64/bin/clang.exe', 'cpp': 'C:/msys64/clang64/bin/clang++.exe'}
tools.cmake.cmaketoolchain:generator=Ninja
tools.env.virtualenv:powershell=True
tools.microsoft.msbuild:installation_path=""
[buildenv]
PATH+=(path)C:/msys64/clang64/bin
[runenv]
PATH+=(path)C:/msys64/clang64/bin


======== Computing dependency graph ========
zlib/1.2.11: Not found in local cache, looking in remotes...
zlib/1.2.11: Checking remote: conancenter
zlib/1.2.11: Downloaded recipe revision fca992a7d96a1b92bd956caa8a97d18f
Graph root
    conanfile.txt: C:\Users\Marcel\source\c-and-cpp\examples2\tutorial\consuming_packages\simple_cmake_project\conanfile.txt
Requirements
    zlib/1.2.11#fca992a7d96a1b92bd956caa8a97d18f - Downloaded (conancenter)

======== Computing necessary packages ========
Requirements
    zlib/1.2.11#fca992a7d96a1b92bd956caa8a97d18f:f31972e2002aeb6fb3f7f5bb889b52794c5199af - Build

======== Installing packages ========
zlib/1.2.11: Sources downloaded from 'conancenter'
zlib/1.2.11: Calling source() in C:\Users\Marcel\.conan2\p\zlibdb1c5346ffee7\s\src

-------- Installing package zlib/1.2.11 (1 of 1) --------
zlib/1.2.11: Building from source
zlib/1.2.11: Package zlib/1.2.11:f31972e2002aeb6fb3f7f5bb889b52794c5199af
zlib/1.2.11: Copying sources to build folder
zlib/1.2.11: Building your package in C:\Users\Marcel\.conan2\p\b\zlibdb7ac87753258\b
zlib/1.2.11: Calling generate()
zlib/1.2.11: Generators folder: C:\Users\Marcel\.conan2\p\b\zlibdb7ac87753258\b\build\Release\generators
zlib/1.2.11: CMakeToolchain generated: conan_toolchain.cmake
zlib/1.2.11: CMakeToolchain generated: CMakePresets.json
zlib/1.2.11: CMakeToolchain generated: ..\..\..\src\CMakeUserPresets.json
zlib/1.2.11: Generating aggregated env files
zlib/1.2.11: Generated aggregated env files: ['conanbuild.ps1', 'conanrun.ps1']
zlib/1.2.11: Calling build()
zlib/1.2.11: Apply patch (conan): separate static/shared builds, disable debug suffix, disable building examples
zlib/1.2.11: Apply patch (portability): fix condition for WIDECHAR usage
zlib/1.2.11: Running CMake.configure()
zlib/1.2.11: RUN: cmake -G "Ninja" -DCMAKE_TOOLCHAIN_FILE="C:/Users/Marcel/.conan2/p/b/zlibdb7ac87753258/b/build/Release/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/Users/Marcel/.conan2/p/b/zlibdb7ac87753258/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "C:\Users\Marcel\.conan2\p\b\zlibdb7ac87753258\b\src"
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Using Conan toolchain: C:/Users/Marcel/.conan2/p/b/zlibdb7ac87753258/b/build/Release/generators/conan_toolchain.cmake
-- Conan toolchain: Setting BUILD_SHARED_LIBS = OFF
-- The C compiler identification is Clang 18.1.2
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/clang64/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of off64_t
-- Check size of off64_t - done
-- Looking for fseeko
-- Looking for fseeko - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Renaming
--     C:/Users/Marcel/.conan2/p/b/zlibdb7ac87753258/b/src/zconf.h
-- to 'zconf.h.included' because this file is included with zlib
-- but CMake generates it automatically in the build directory.
-- Configuring done (2.8s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/Marcel/.conan2/p/b/zlibdb7ac87753258/b/build/Release

zlib/1.2.11: Running CMake.build()
zlib/1.2.11: RUN: cmake --build "C:\Users\Marcel\.conan2\p\b\zlibdb7ac87753258\b\build\Release" -- -j16
[1/16] Building C object CMakeFiles/zlib.dir/uncompr.c.obj
C:/Users/Marcel/.conan2/p/b/zlibdb7ac87753258/b/src/uncompr.c:27:13: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C23 [-Wdeprecated-non-prototype]
   27 | int ZEXPORT uncompress2 (dest, destLen, source, sourceLen)
      |             ^
C:/Users/Marcel/.conan2/p/b/zlibdb7ac87753258/b/src/uncompr.c:86:13: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C23 [-Wdeprecated-non-prototype]
   86 | int ZEXPORT uncompress (dest, destLen, source, sourceLen)
      |             ^
2 warnings generated.

[... A bunch of warnings generated ...]

22 warnings generated.
[16/16] Linking C static library libz.a

zlib/1.2.11: Package 'f31972e2002aeb6fb3f7f5bb889b52794c5199af' built
zlib/1.2.11: Build folder C:\Users\Marcel\.conan2\p\b\zlibdb7ac87753258\b\build\Release
zlib/1.2.11: Generating the package
zlib/1.2.11: Packaging in folder C:\Users\Marcel\.conan2\p\b\zlibdb7ac87753258\p
zlib/1.2.11: Calling package()
zlib/1.2.11: Running CMake.install()
zlib/1.2.11: RUN: cmake --install "C:\Users\Marcel\.conan2\p\b\zlibdb7ac87753258\b\build\Release" --prefix "C:/Users/Marcel/.conan2/p/b/zlibdb7ac87753258/p"
-- Install configuration: "Release"
-- Installing: C:/Users/Marcel/.conan2/p/b/zlibdb7ac87753258/p/lib/libz.a
-- Installing: C:/Users/Marcel/.conan2/p/b/zlibdb7ac87753258/p/include/zconf.h
-- Installing: C:/Users/Marcel/.conan2/p/b/zlibdb7ac87753258/p/include/zlib.h

zlib/1.2.11: package(): Packaged 2 '.h' files: zconf.h, zlib.h
zlib/1.2.11: package(): Packaged 1 '.a' file: libz.a
zlib/1.2.11: package(): Packaged 1 file: LICENSE
zlib/1.2.11: Created package revision 208eb55526fe962745b4b162cc7e378e
zlib/1.2.11: Package 'f31972e2002aeb6fb3f7f5bb889b52794c5199af' created
zlib/1.2.11: Full package reference: zlib/1.2.11#fca992a7d96a1b92bd956caa8a97d18f:f31972e2002aeb6fb3f7f5bb889b52794c5199af#208eb55526fe962745b4b162cc7e378e
zlib/1.2.11: Package folder C:\Users\Marcel\.conan2\p\b\zlibdb7ac87753258\p
WARN: deprecated: Usage of deprecated Conan 1.X features that will be removed in Conan 2.X:
WARN: deprecated:     'cpp_info.names' used in: zlib/1.2.11

======== Finalizing install (deploy, generators) ========
conanfile.txt: Writing generators to C:\Users\Marcel\source\c-and-cpp\examples2\tutorial\consuming_packages\simple_cmake_project\build
conanfile.txt: Generator 'CMakeDeps' calling 'generate()'
conanfile.txt: CMakeDeps necessary find_package() and targets for your CMakeLists.txt
    find_package(ZLIB)
    target_link_libraries(... ZLIB::ZLIB)
conanfile.txt: Generator 'CMakeToolchain' calling 'generate()'
conanfile.txt: CMakeToolchain generated: conan_toolchain.cmake
conanfile.txt: Preset 'conan-release' added to CMakePresets.json. Invoke it manually using 'cmake --preset conan-release' if using CMake>=3.23
conanfile.txt: If your CMake version is not compatible with CMakePresets (<3.23) call cmake like: 'cmake <path> -G Ninja -DCMAKE_TOOLCHAIN_FILE=C:\Users\Marcel\source\c-and-cpp\examples2\tutorial\consuming_packages\simple_cmake_project\build\conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release'
conanfile.txt: CMakeToolchain generated: CMakePresets.json
conanfile.txt: CMakeToolchain generated: ..\CMakeUserPresets.json
conanfile.txt: Generating aggregated env files
conanfile.txt: Generated aggregated env files: ['conanbuild.ps1', 'conanrun.ps1']
Install finished successfully

=> cmake --preset conan-release
Preset CMake variables:

  CMAKE_BUILD_TYPE="Release"
  CMAKE_POLICY_DEFAULT_CMP0091="NEW"
  CMAKE_TOOLCHAIN_FILE:FILEPATH="C:\Users\Marcel\source\c-and-cpp\examples2\tutorial\consuming_packages\simple_cmake_project\build\conan_toolchain.cmake"

Preset environment variables:

  PATH="C:\Program Files\PowerShell\7;D:\dev_tools\python\Scripts\;D:\dev_tools\python\;D:\dev_tools\VulkanSDK\Bin;c:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowspowershell\v1.0\;c:\windows\system32\openssh\;c:\program files (x86)\gnupg\bin;D:\dev_tools\git\bin;c:\msys64\usr\bin;c:\msys64\clang64\bin;D:\dev_tools\cmake\bin;D:\dev_tools\ninja\bin;D:\dev_tools\node;D:\dev_tools\jdk\bin;D:\dev_tools\Android\cmdline-tools\latest\bin;D:\dev_tools\Android\platform-tools;D:\dev_tools\Android\emulator;D:\dev_tools\watchman\bin;c:\program files\dotnet\;C:\Program Files\PowerShell\7\;C:\Users\Marcel\AppData\Local\Microsoft\WindowsApps;C:\Users\Marcel\AppData\Local\Programs\oh-my-posh\bin;C:\Users\Marcel\AppData\Local\Programs\Microsoft VS Code\bin;;C:\Users\Marcel\AppData\Local\Programs\oh-my-posh\bin;C:\Users\Marcel\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Marcel\.dotnet\tools;C:/msys64/clang64/bin"

-- Using Conan toolchain: C:/Users/Marcel/source/c-and-cpp/examples2/tutorial/consuming_packages/simple_cmake_project/build/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 20 with extensions OFF
-- The C compiler identification is Clang 18.1.2
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/clang64/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Conan: Target declared 'ZLIB::ZLIB'
CMake Error at build/cmakedeps_macros.cmake:67 (message):
  Library 'zlib' not found in package.  If 'zlib' is a system library,
  declare it with 'cpp_info.system_libs' property
Call Stack (most recent call first):
  build/ZLIB-Target-release.cmake:23 (conan_package_library_targets)
  build/ZLIBTargets.cmake:24 (include)
  build/ZLIBConfig.cmake:16 (include)
  CMakeLists.txt:4 (find_package)


-- Configuring incomplete, errors occurred!

If you would need any further information, please let me know. I hope someone could help me resolve this issue, thanks in advance!

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@TheWirv TheWirv changed the title [question] "Library 'zlib' no found in package." error during first tutorial [question] Error "Library 'zlib' not found in package." during first tutorial Apr 1, 2024
@TheWirv
Copy link
Author

TheWirv commented Apr 1, 2024

I have zipped up the repo, incl. the generated build dir and CmakeUserPresets.json here.

simple_cmake_project.zip

@memsharded
Copy link
Member

Hi @TheWirv

Thanks for your report, and thanks specially for the details to reproduce, it really helps.

This doesn't seem a Conan issue, but this is a recipe limitation for zlib in ConanCenter.
Recipes in ConanCenter are built and tested for a bunch of configurations, like different flavors and versions of MSVC in Windows, Gcc/clang in Linux, etc. Some users also contribute improvements to support Mingw and other compilers like clang (LLVM/Clang mostly, not msys2/clang).

It seems that the recipe in this case is generating for this msys2/clang:

set(zlib_LIBS_RELEASE zlib)

But the actual file name is libz.a, and this is the reason the find_package() cannot find it.

A good idea to test if something is a Conan issue or a recipe issue is to test it with the conan new cmake_lib -d name=pkg -d version=0.1 template.

I am moving this to conan-center-index repo, but the backlog there is very large, it might take a while.

I'd also like to do some suggestions in the meantime, maybe these help:

  • I'd recommend to decouple the learning of Conan from the later prod usage specially if planning to use msys2/clang, and consider the mainstream msvc compiler for Windows, to do the tutorials, etc.
  • I'd also probably recommend LLVM/Clang for Win, better than msys2/clang, it seems it has a much wider adoption by the community, so it is likely that recipes in ConanCenter will have better support (https://blog.conan.io/2022/10/13/Different-flavors-Clang-compiler-Windows.html for a comparison, maybe it is useful)
  • For working with ConanCenter recipes, for special configurations it can be useful to work from a fork of conan-center-index, so modifications and testing to the recipes there is easier

@memsharded memsharded transferred this issue from conan-io/conan Apr 1, 2024
@SpaceIm
Copy link
Contributor

SpaceIm commented Apr 1, 2024

Well known issue with clang flavors on Windows. I've proposed #14644 & conan-io/conan#12678, but it never made its way into code base, so we can't really properly support MinGW clang on Windows in conancenter (it's sort of a mess where every cci contributor comes with its own interpretation of how to detect MinGW or clang flavor based on conan profile).

@TheWirv
Copy link
Author

TheWirv commented Apr 2, 2024

Hi guys, thanks so much for the quick and very detailed answers!

Well, I suppose I'll switch to LLVM/clang then. I used MSYS2 clang because the version distributed by the LLVM project directly has some MSVC dependency on Windows, and I'm trying to avoid using proprietary Microsoft tools as much as possible. But, coming from a JavaScript/TypeScript background, I gotta admit that the DX of having a package/dependency manager is more important to me than my anti M$ crusade. 😅

I'll report back when I have set up my new toolchain, and have successfully finished the tutorial. Then, I'll also close this thread, thank you!

@memsharded
Copy link
Member

Well, I suppose I'll switch to LLVM/clang then. I used MSYS2 clang because the version distributed by the LLVM project directly has some MSVC dependency on Windows, and I'm trying to avoid using proprietary Microsoft tools as much as possible. But, coming from a JavaScript/TypeScript background, I gotta admit that the DX of having a package/dependency manager is more important to me than my anti M$ crusade.

Definitely, but it is also fair to admit that Microsoft has been doing a good job contributing in open source some great things, and opening in general. Even being able to use easily msvc with the community editions is also a good experience. At the end of the day, if the built software has to run on windows, having the LLVM/Clang dependency on the msvc runtime is not a big deal, as the blog post shows, also msys2/clang has a dependency on api-ms-win-crt-*.dll!

@TheWirv
Copy link
Author

TheWirv commented Apr 2, 2024

Definitely, but it is also fair to admit that Microsoft has been doing a good job contributing in open source some great things, and opening in general. Even being able to use easily msvc with the community editions is also a good experience. At the end of the day, if the built software has to run on windows, having the LLVM/Clang dependency on the msvc runtime is not a big deal, as the blog post shows, also msys2/clang has a dependency on api-ms-win-crt-*.dll!

You're absolutely right! And I can confirm: After having installed MSVC and LLVM/Clang, I am able to successfully build the example from the tutorial, thanks for the help!

@TheWirv TheWirv closed this as completed Apr 2, 2024
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

3 participants