Vcpkg: Error while cross-compiling zlib on Linux for Windows

Created on 28 Aug 2020  路  2Comments  路  Source: microsoft/vcpkg

Describe the bug
ZLIB triies to find libz but its named zlib.lib on Windows

Environment

  • OS: Linux cross-compiling for Windows
  • Compiler: Clang + LLVM 9

To Reproduce
Steps to reproduce the behavior:

  1. ./vcpkg --debug --triplet x86-windows-release install zlib:x86-windows-release
  2. See error
    CMake Error at scripts/cmake/vcpkg_fixup_pkgconfig.cmake:232 (message):
    Library "z" was not found! If it is a system library use the
    SYSTEM_LIBRARIES parameter for the vcpkg_fixup_pkgconfig call! Otherwise,
    correct the *.pc file
    Call Stack (most recent call first):
    scripts/cmake/vcpkg_fixup_pkgconfig.cmake:298 (vcpkg_fixup_pkgconfig_check_files)
    ports/zlib/portfile.cmake:50 (vcpkg_fixup_pkgconfig)
    scripts/ports.cmake:79 (include)

Expected behavior
It should look for zlib.lib when cross-compiling

Fix
It seems the variable VCPKG_TARGET_IS_WINDOWS in scripts/cmake/vcpkg_common_definitions.cmake is not set when cross-compiling.
Maybe you should add a check for the Windows target if VCPKG_CMAKE_SYSTEM_NAME is Windows.

For now, I've added set(VCPKG_TARGET_IS_WINDOWS 1) in my triplet and that fixes the zlib build.

Additional context
My custom triplet:

set(VCPKG_TARGET_ARCHITECTURE x86)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)

set(VCPKG_BUILD_TYPE release)

set(VCPKG_CMAKE_SYSTEM_NAME Windows)

# For clang_windows toolchain
set(ENV{HOST_ARCH} ${VCPKG_TARGET_ARCHITECTURE})

set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE /clang_windows_sdk/clang-cl-msvc.cmake)
question

Most helpful comment

set(VCPKG_CMAKE_SYSTEM_NAME Windows)

unset this and instead add
set(CMAKE_SYSTEM_NAME Windows)
into your toolchain

within vcpkg and unset VCPKG_CMAKE_SYSTEM_NAME means Windows.

All 2 comments

set(VCPKG_CMAKE_SYSTEM_NAME Windows)

unset this and instead add
set(CMAKE_SYSTEM_NAME Windows)
into your toolchain

within vcpkg and unset VCPKG_CMAKE_SYSTEM_NAME means Windows.

set(VCPKG_CMAKE_SYSTEM_NAME Windows)

unset this and instead add
set(CMAKE_SYSTEM_NAME Windows)
into your toolchain

within vcpkg and unset VCPKG_CMAKE_SYSTEM_NAME means Windows.

It is already set in my toolchain.

Was this page helpful?
0 / 5 - 0 ratings