Describe the bug
When trying to install a static version of a port, vcpkg fails with:
Expected Debug,Static crt linkage, but the following libs had invalid crt linkage:
Expected Release,Static crt linkage, but the following libs had invalid crt linkage:
It looks like this happens since commit https://github.com/microsoft/vcpkg/commit/da0a15485256837569d0e6b00a5940757ff57971
Environment
To Reproduce
Steps to reproduce the behavior:
Computing installation plan...
The following packages will be built and installed:
zlib[core]:x64-windows-static
Starting package 1/1: zlib:x64-windows-static
Building package zlib[core]:x64-windows-static...
-- Using cached C:/Users/XXXXXX/vcpkg/downloads/zlib1211.tar.gz
-- Using source at C:/Users/XXXXXX/vcpkg/buildtrees/zlib/src/1.2.11-deec42f53b
-- Configuring x64-windows-static
-- Building x64-windows-static-dbg
-- Building x64-windows-static-rel
-- Installing: C:/Users/XXXXXX/vcpkg/packages/zlib_x64-windows-static/share/zlib/copyright
-- Performing post-build validation
Expected Debug,Static crt linkage, but the following libs had invalid crt linkage:
C:/Users/XXXXXX/vcpkg/packages/zlib_x64-windows-static/debug/lib/zlibd.lib: Debug,Dynamic
To inspect the lib files, use:
dumpbin.exe /directives mylibfile.lib
Expected Release,Static crt linkage, but the following libs had invalid crt linkage:
C:/Users/XXXXXX/vcpkg/packages/zlib_x64-windows-static/lib/zlib.lib: Release,Dynamic
To inspect the lib files, use:
dumpbin.exe /directives mylibfile.lib
Found 2 error(s). Please correct the portfile:
C:\Users\XXXXXX\vcpkg\ports\zlib\portfile.cmake
-- Performing post-build validation done
Error: Building package zlib:x64-windows-static failed with: POST_BUILD_CHECKS_FAILED
Expected behavior
vcpkg install zlib:x64-windows-static
Computing installation plan...
The following packages will be built and installed:
zlib[core]:x64-windows-static
Starting package 1/1: zlib:x64-windows-static
Building package zlib[core]:x64-windows-static...
-- Using cached C:/Users/XXXXXX/vcpkg/downloads/zlib1211.tar.gz
-- Using source at C:/Users/XXXXXX/vcpkg/buildtrees/zlib/src/1.2.11-deec42f53b
-- Configuring x64-windows-static
-- Building x64-windows-static-dbg
-- Building x64-windows-static-rel
-- Installing: C:/Users/XXXXXX/vcpkg/packages/zlib_x64-windows-static/share/zlib/copyright
-- Performing post-build validation
-- Performing post-build validation done
Building package zlib[core]:x64-windows-static... done
Installing package zlib[core]:x64-windows-static...
Installing package zlib[core]:x64-windows-static... done
Elapsed time for package zlib:x64-windows-static: 6.866 s
Total elapsed time: 6.868 s
The package zlib is compatible with built-in CMake targets:
find_package(ZLIB REQUIRED)
target_link_libraries(main PRIVATE ZLIB::ZLIB)
Failure logs
-(please attached failure logs)
Additional context
Add any other context about the problem here.
Same issue here ...
Fixing... that's critical.
Related PR: #10485 #10486 #10285.
Seems to be a CMake bug. In setting up the variables on Windows. Don't know if the other platforms are also effected. But I see a doubling of compiler flags:
-- CMAKE_C_FLAGS:/DWIN32 /D_WINDOWS /W3 /utf-8 /MP /DWIN32 /D_WINDOWS /W3
-- CMAKE_C_FLAGS_DEBUG:/D_DEBUG /MTd /Z7 /Ob0 /Od /RTC1 /MDd /Zi /Ob0 /Od /RTC1
-- CMAKE_C_FLAGS_RELEASE:/MT /O2 /Oi /Gy /DNDEBUG /Z7 /MD /O2 /Ob2 /DNDEBUG
while the _INIT flags are correctly setup
Thank's for reporting this issue!
Already fixed, please update vcpkg and try again.
Seems to be a CMake bug. In setting up the variables on Windows. Don't know if the other platforms are also effected. But I see a doubling of compiler flags:
-- CMAKE_C_FLAGS:/DWIN32 /D_WINDOWS /W3 /utf-8 /MP /DWIN32 /D_WINDOWS /W3 -- CMAKE_C_FLAGS_DEBUG:/D_DEBUG /MTd /Z7 /Ob0 /Od /RTC1 /MDd /Zi /Ob0 /Od /RTC1 -- CMAKE_C_FLAGS_RELEASE:/MT /O2 /Oi /Gy /DNDEBUG /Z7 /MD /O2 /Ob2 /DNDEBUGwhile the
_INITflags are correctly setup
Not sure it's a cmake bug. INIT variables are allowed to be modified by cmake itself to append or prepend flags based on default values (which are dynamic builds...) to prepare the flags in cache, which are empty if you don't define them.
OTOH, if you already set the flags in cache, CMake will not touch them.
https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS_INIT.html
Most helpful comment
Thank's for reporting this issue!
Already fixed, please update vcpkg and try again.