Skip to content

rustc does not add the LIBPATH for ucrt.lib to the MSVC command line. #27402

Closed
@briansmith

Description

@briansmith

When cargo build is used outside of an VS2015 {x86,x64} Native Tools Command Prompt, I receive this error during linking:

rustc: LINK : fatal error LNK1104: cannot open file 'ucrt.lib'

in librustc_trans/back/msvc/mod.rs:

    // The MSVC linker uses the LIB environment variable as the default lookup
    // path for libraries. This environment variable is normally set up by the
    // VS shells, so we only want to start adding our own pieces if it's not
    // set.
    //
    // If we're adding our own pieces, then we need to add two primary
    // directories to the default search path for the linker. The first is in
    // the VS install direcotry and the next is the Windows SDK directory.

When building using the VS2015 toolkit, there is a third path needed: The path to ucrt.lib. On my system, it is C:\Program Files (x86)\Windows Kits\10\lib\10.0.10150.0\ucrt\x64. Here is the full value of the LIB environment variable that vcvarsall.bat sets:

LIB=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64;C:\ProgramFiles (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.10150.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\lib\um\x64;C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64;

Here's the build output, reformatted so every parameter is on its own line:

error: linking with `link.exe` failed: exit code: 1104
note: "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC/bin\amd64\link.exe"
"/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC/lib\amd64"
"/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64"
"/NOLOGO"
"/NXCOMPAT"
"/LIBPATH:C:\Users\Example\AppData\Local\Apps\Rust-1.3\bin\rustlib\x86_64-pc-windows-msvc\lib"
"C:\Users\Example\Documents\p\ring\target\debug\build\ring-c7da49b4c8d6e8fe\build_script_build.0.o"
"/OUT:C:\Users\Example\Documents\p\ring\target\debug\build\ring-c7da49b4c8d6e8fe\build_script_build.exe"
"/OPT:REF,ICF"
"/DEBUG"
"/LIBPATH:C:\Users\Example\AppData\Local\Apps\Rust-1.3\bin\rustlib\x86_64-pc-windows-msvc\lib"
"std-74fa456f.lib"
"/LIBPATH:C:\Users\Example\Documents\p\ring\target\debug"
"/LIBPATH:C:\Users\Example\Documents\p\ring\target\debug\deps"
"/LIBPATH:C:\Users\Example\AppData\Local\Apps\Rust-1
.3\bin\rustlib\x86_64-pc-windows-msvc\lib"
"/LIBPATH:C:\Users\Example\Documents\p\ring\.rust\bin\x86_64-pc-windows-msvc"
"/LIBPATH:C:\Users\Example\Documents\p\ring\bin\x86_64-pc-windows-msvc"
"ws2_32.lib"
"userenv.lib"
"advapi32.lib"
"kernel32.lib"
"shell32.lib"
"msvcrt.lib"
"compiler-rt.lib"
note: LINK : fatal error LNK1104: cannot open file 'ucrt.lib'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions