Skip to content

Unable to link rust static lib to C code on 1.57.0 #91974

Open
@PunitLodha

Description

@PunitLodha

I am working on ccextractor, and recently the tests failed on rustc 1.57.0, with the error:-

"D:\a\ccextractor\ccextractor\windows\ccextractor.sln" (default target) (1) ->
"D:\a\ccextractor\ccextractor\windows\ccextractor.vcxproj" (default target) (2) ->
(Link target) -> 
  ccx_rust.lib(std-f87c887dcbebcf7e.std.06878a67-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol __imp_BCryptGenRandom referenced in function _ZN3std6thread5local4fast12Key$LT$T$GT$14try_initialize17h6f0eaa92973cfc73E [D:\a\ccextractor\ccextractor\windows\ccextractor.vcxproj]
  D:\a\ccextractor\ccextractor\windows\x64\Release\ccextractorwin.exe : fatal error LNK1120: 1 unresolved externals [D:\a\ccextractor\ccextractor\windows\ccextractor.vcxproj]

Error relates to an undefined symbol __imp_BCryptGenRandom referenced in std:: thread::localfastkey::try_initialize
Switching to rustc 1.56.0 or below does not cause any errors

Here are the logs for 1.57.0 test run, and here for 1.56.0 test run.

Looking into the static libraries, only the lib built with 1.57.0 has the symbol specified in the error

C:\ccextractor>dumpbin /symbols ccx_rust_1-56.lib | FIND "BCrypt"

C:\ccextractor>dumpbin /symbols ccx_rust_1-57.lib | FIND "BCrypt"
3283 00000000 UNDEF  notype       External     | __imp_BCryptGenRandom

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-windowsOperating system: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions