Can't build targeting msvc

Hi guys,

I'm trying to setup a project targeting x86_64-pc-windows-msvc; however, I'm not even getting started. :cry: I can get it working targeting x86_64-pc-windows-gnu, so I think there's probably something I'm missing that I'm not aware of, but I can't figure out what.

I've setup probably the simplest test case to show where it's failing:

C:\Users\Charles\Repos>cargo new test

C:\Users\Charles\Repos>cd test

C:\Users\Charles\Repos\test>cargo build
    Compiling test v0.1.0 (file:///C:/Users/Charles/Repos/test)

C:\Users\Charles\Repos\test>cargo build --target x86_64-pc-windows-msvc --verbose
    Compiling test v0.1.0 (file:///C:/Users/Charles/Repos/test)
      Running `rustc src\lib.rs --crate-name test
         --crate-type lib -g
         --out-dir C:\Users\Charles\Repos\test\target\x86_64-pc-windows-msvc\debug
         --emit=dep-info,link
         --target x86_64-pc-windows-msvc -L dependency=C:\Users\Charles\Repos\test\target\x86_64-pc-windows-msvc\debug -L dependency=C:\Users\Charles\Repos\test\target\x86_64-pc-windows-msvc\debug\deps`
src\lib.rs:1:1: 1:1 error: can't find crate for `std`
src\lib.rs:1 #[test]
             ^
error: aborting due to previous error
Could not compile `test`.

Caused by:
  Process didn't exit successfully: `rustc src\lib.rs
     --crate-name test
     --crate-type lib -g
     --out-dir C:\Users\Charles\Repos\test\target\x86_64-pc-windows-msvc\debug
     --emit=dep-info,link
     --target x86_64-pc-windows-msvc -L dependency=C:\Users\Charles\Repos\test\target\x86_64-pc-windows-msvc\debug -L dependency=C:\Users\Charles\Repos\test\target\x86_64-pc-windows-msvc\debug\deps` (exit code: 101)

I verified my path does include cl.exe here: ;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64. I've also tried with the current Stable and Beta Rust versions, getting the same results (installed to default locations).

Any ideas?

Rust ships with libraries only for the same target triple that the compiler itself was built for. You've probably installed the x86_64-pc-windows-gnu version, which won't have libraries for x86_64-pc-windows-msvc.

The easiest fix in your case is to download version for the triple you want to target: https://static.rust-lang.org/dist/rust-nightly-x86_64-pc-windows-msvc.msi (it isn't shown on the downloads page, since msvc support is still experimental.

1 Like

Gotcha, I thought I read that it was becoming a supported taget in 1.4, so I was half expecting it not to work in 1.3, but I was expecting it to work in 1.4. That would definitely explain my issues. Thanks!

Edit: Just to confirm, this did indeed fix my issue! Thanks again!