Using a custom Windows container that contains Visual Studio 2015 Enterprise Update 3 full installation, Windows 10 SDK full installation on a X64 base OS.
Compiling a simple HelloWorld.rs program with no dependencies etc.
I get the following error.
Is there a specific flag I have to pass in? I did run the vsvars32.bat batch file to set the appropriate environment variables for VC.
error: linking with `link.exe` failed: exit code: 1112
|
= note: "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Program Files\\Rust stable MSVC 1.18\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "HelloWorld.0.o" "/OUT:HelloWorld.exe" "/OPT:REF,NOICF" "/DEBUG" "/LIBPATH:C:\\Program Files\\Rust stable MSVC 1.18\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Program Files\\Rust stable MSVC 1.18\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-0a78323911070f99.rlib" "C:\\Program Files\\Rust stable MSVC 1.18\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librand-c279a51d66700350.rlib" "C:\\Program Files\\Rust stable MSVC 1.18\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcollections-d7bf31a4ca1ea637.rlib" "C:\\Program Files\\Rust stable MSVC 1.18\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_unicode-d367c3ba0db49600.rlib" "C:\\Program Files\\Rust stable MSVC 1.18\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-2d4bf02140c11dcb.rlib" "C:\\Program Files\\Rust stable MSVC 1.18\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-add7a84d7e82d084.rlib" "C:\\Program Files\\Rust stable MSVC 1.18\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-84688accbc86d6b7.rlib" "C:\\Program Files\\Rust stable MSVC 1.18\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-fe2e68b21f0bdd7a.rlib" "C:\\Program Files\\Rust stable MSVC 1.18\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc_system-7fc0381594c93f56.rlib" "C:\\Program Files\\Rust stable MSVC 1.18\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-ea9d77e7c23fe65c.rlib" "C:\\Program Files\\Rust stable MSVC 1.18\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-91b619d34dd1f5aa.rlib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "shell32.lib" "msvcrt.lib"
= note: msvcrt.lib(chkstk.obj) : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'
vsvars32.bat
configures your environment to build 32-bit binaries.
The rust toolchain you're using is x86_64-pc-windows-msvc
which builds 64-bit binaries.
Hence the error message telling you that there are conflicting architectures.
I recommend switching to vcvars64.bat
to configure your environment.
This is not a Rust bug per se. Maybe the situation can be detected by cargo to produce a better error message. Having some sort of FAQ for common pitfalls like this in the installation section of the website might be a good idea as well.
Some VS Code C++ tutorials encourage starting "code" from the developer command prompt. I faced the LNK1112 issue, and it turned out I had accidentally started VS Code using the 32-bit developer command prompt (alas still the default). Starting VS Code from a 64-bit prompt, or simply from the Windows Start Menu, removed the issue.
I had the same issue when running the rust compiler on Developer Command Prompt for VS 2019:
rustc 1.39.0 (4560ea788 2019-11-04)
:Windows 10 x64
error: linking with `link.exe` failed: exit code: 1112
|
= note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.23.28105\\bin\\HostX86\\x86\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "main.main.7rcbfp3g-cgu.0.rcgu.o" "main.main.7rcbfp3g-cgu.1.rcgu.o" "main.main.7rcbfp3g-cgu.2.rcgu.o" "main.main.7rcbfp3g-cgu.3.rcgu.o" "main.main.7rcbfp3g-cgu.4.rcgu.o" "main.main.7rcbfp3g-cgu.5.rcgu.o" "/OUT:main.exe" "main.4s37gsrti678ik8u.rcgu.o" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/LIBPATH:C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-f3cd9033b21bfd69.rlib" "C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-7177cc63e2247a71.rlib" "C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-dc4f9fa6045181bb.rlib" "C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-b42f2443bfe541d3.rlib" "C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libbacktrace-727167d019576e4a.rlib" "C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-b116c11df52ba1e2.rlib" "C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-d4c5a28b76348d5c.rlib" "C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-79bcbf9ce75fa48d.rlib" "C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-c9478dd7b586b8cc.rlib" "C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-c80eff7d74f3988c.rlib" "C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-fd0f5d5cd3b3863d.rlib" "C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-49f9f21b6d32d457.rlib" "C:\\Users\\augustoproiete\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-b32ee8ba444e5f7c.rlib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
= note: msvcrt.lib(chkstk.obj) : fatal error LNK1112: module machine type 'x86' conflicts with target machine type 'x64'
error: aborting due to previous error
It also left a number of temporary files on disk:
Running rustc
or cargo
from a regular command-prompt works fine, but it would be great if the message was more informative.
In regular Windows PowerShell without path tweaks for Visual Studio, link.exe
is not found in the command path, so cargo appears to magically discover the absolute path name in the x64 tools directory, which is the correct one. The host architecture of the shell does not affect this behavior.
Unfortunately, the launchers named Developer PowerShell and Developer Command Prompt for VS 2019 set up the command path for x86 tools. Perhaps it would be better for cargo to ignore the PATH-located executable on Windows if the registry-resolved tools directory appropriate for the target platform contains the executable file.
Most helpful comment
In regular Windows PowerShell without path tweaks for Visual Studio,
link.exe
is not found in the command path, so cargo appears to magically discover the absolute path name in the x64 tools directory, which is the correct one. The host architecture of the shell does not affect this behavior.Unfortunately, the launchers named Developer PowerShell and Developer Command Prompt for VS 2019 set up the command path for x86 tools. Perhaps it would be better for cargo to ignore the PATH-located executable on Windows if the registry-resolved tools directory appropriate for the target platform contains the executable file.