Skip to content

Rust 1.79+ stdlib is unusable with MSVC when creating static libraries #129020

Closed
@amyspark

Description

Code

I tried to build librsvg using a simple meson setup build -Ddefault_library=both then meson compile -C build.

I expected to see this happen: linking success.

Instead, this happened: MSVC link returns LNK2005 and fails to /WHOLEARCHIVE the static library.

Version it worked on

It most recently worked on: 1.77.2

Version with regression

rustc --version --verbose:

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-pc-windows-msvc
release: 1.79.0
LLVM version: 18.1.7

This is caused by both #121337 and #124019. When creating stdlibs, each MR causes the Rust compiler to add an export of __NULL_IMPORT_DESCRIPTOR; one comes from api-ms-win-core-synch-l1-2-0.dll and the other from bcryptprimitives.dll. This error will not be found until one consumes the Rust-generated library.

I am filing this report to consolidate the ones in rust-lang/cc-rs#1167 (comment) and mesonbuild/meson#13236 (comment).

Backtrace

Backtrace

[4/6] "link"  /MACHINE:x64 /OUT:rsvg/rsvg-2-2.dll rsvg/rsvg-2-2.dll.p/meson-generated_..__rsvg_dummy.c.obj "/LIBPATH:E:/cerbero-sources/dist/msvc_x86_64/lib" "/release" "/nologo" "/DEBUG" "/PDB:rsvg\rsvg-2-2.pdb" "/DLL" "/DEF:rsvg\librsvg-2.0.def" "/IMPLIB:rsvg\rsvg-2.lib" "/WHOLEARCHIVE:rsvg/rsvg_2.lib" "rsvg/rsvg_2.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/cairo.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/cairo-gobject.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/gobject-2.0.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/glib-2.0.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/intl.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/png16.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/z.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/dav1d.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/freetype.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/gdk_pixbuf-2.0.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/gio-2.0.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/harfbuzz.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/xml2.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/pangocairo-1.0.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/pango-1.0.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/pangoft2-1.0.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/fontconfig.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/gmodule-2.0.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "kernel32.lib" "/defaultlib:msvcrt.lib" "ntdll.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib"
FAILED: rsvg/rsvg-2-2.dll rsvg/rsvg-2-2.pdb
"link"  /MACHINE:x64 /OUT:rsvg/rsvg-2-2.dll rsvg/rsvg-2-2.dll.p/meson-generated_..__rsvg_dummy.c.obj "/LIBPATH:E:/cerbero-sources/dist/msvc_x86_64/lib" "/release" "/nologo" "/DEBUG" "/PDB:rsvg\rsvg-2-2.pdb" "/DLL" "/DEF:rsvg\librsvg-2.0.def" "/IMPLIB:rsvg\rsvg-2.lib" "/WHOLEARCHIVE:rsvg/rsvg_2.lib" "rsvg/rsvg_2.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/cairo.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/cairo-gobject.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/gobject-2.0.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/glib-2.0.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/intl.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/png16.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/z.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/dav1d.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/freetype.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/gdk_pixbuf-2.0.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/gio-2.0.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/harfbuzz.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/xml2.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/pangocairo-1.0.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/pango-1.0.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/pangoft2-1.0.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/fontconfig.lib" "E:/cerbero-sources/dist/msvc_x86_64/lib/gmodule-2.0.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "kernel32.lib" "/defaultlib:msvcrt.lib" "ntdll.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib"
rsvg_2.lib(api-ms-win-core-synch-l1-2-0.dll) : error LNK2005: __NULL_IMPORT_DESCRIPTOR already defined in rsvg_2.lib(bcryptprimitives.dll)

   Creating library rsvg\rsvg-2.lib and object rsvg\rsvg-2.exp

rsvg\rsvg-2-2.dll : fatal error LNK1169: one or more multiply defined symbols found

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-windows-msvcToolchain: MSVC, Operating system: WindowsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions