Skip to content

[libpq] windows-static triplets install DLL import lib instead of static lib (libpq.a not copied) #51102

Description

@ej-yamazaki

Describe the bug
On Windows MSVC, installing libpq with x64-windows-static or
x86-windows-static triplets results in the DLL import library being
installed as lib/libpq.lib (42 KB) instead of the true static library.
The actual static archive libpq.a (2 MB) is built by meson but never
copied to the install tree, causing consumers to link dynamically against
libpq.dll at runtime and transitively load OpenSSL DLLs.

Environment

  • OS: Windows
  • Compiler: MSVC (Visual Studio 2022)
  • vcpkg version: latest

To Reproduce

  1. ./vcpkg install libpq:x64-windows-static
  2. Link a consumer project against libpq.lib
  3. Run the binary — libpq.dll and libcrypto-3-x64.dll are loaded at runtime

Or verify directly:

dir %VCPKG_ROOT%\installed\x64-windows-static\lib\libpq*

libpq.lib is 42 KB (import library, not a static archive)

Expected behavior
installed/x64-windows-static/lib/libpq.lib should be the static archive
(~2 MB), built from libpq.a produced by the meson build.
No libpq.dll should be loaded at runtime.

Failure logs
The bug does not produce a build error. Evidence:

  • buildtrees/libpq/x64-windows-static-rel/src/interfaces/libpq/libpq.a — 2 MB ✅ (built but discarded)
  • installed/x64-windows-static/lib/libpq.lib — 42 KB ❌ (DLL import lib)
  • installed/x64-windows-static/bin/libpq.dll — absent (correctly removed)
  • Consumer binary dynamically loads libpq.dll and libcrypto-3-x64.dll at runtime

Additional context
Root cause is in ports/libpq/build-msvc.cmake.
The static build path removes bin/ but never installs libpq.a as lib/libpq.lib:

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
    # libpq.a is built by meson but never copied here
    file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin")
endif()

Suggested fix — add before the REMOVE_RECURSE:

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
    file(GLOB _static_libs
        "${CURRENT_PACKAGES_DIR}/lib/libpq.a"
        "${CURRENT_PACKAGES_DIR}/debug/lib/libpq.a"
    )
    foreach(_src IN LISTS _static_libs)
        string(REPLACE ".a" ".lib" _dst "${_src}")
        file(COPY_FILE "${_src}" "${_dst}")
        file(REMOVE "${_src}")
    endforeach()

    file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin")
endif()

Note: the Unix/mingw path in portfile.cmake correctly handles
VCPKG_LIBRARY_LINKAGE via LIBPQ_LIBRARY_TYPE. The MSVC path
(build-msvc.cmake) lacks the equivalent handling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions