Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot link with Win32 libraries using the MSVC toolchain #43039

Closed
Tomcc opened this issue Jul 3, 2017 · 20 comments
Closed

Cannot link with Win32 libraries using the MSVC toolchain #43039

Tomcc opened this issue Jul 3, 2017 · 20 comments

Comments

@Tomcc
Copy link

Tomcc commented Jul 3, 2017

I've switched my environment over from GNU to MSVC, to be able to debug in VSCode.
If I try to build anything, I get an error like this one as soon as some win32-specific library is built:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise>cargo install cargo-update
    Updating registry `https://github.com/rust-lang/crates.io-index`
  Installing cargo-update v1.1.1
   Compiling winapi v0.2.8
   Compiling unicode-width v0.1.4
   Compiling vcpkg v0.2.2
   Compiling utf8-ranges v1.0.0
   Compiling bitflags v0.9.1
   Compiling lazy_static v0.2.8
   Compiling libc v0.2.24
   Compiling winapi-build v0.1.1
   Compiling array_tool v0.4.0
   Compiling tabwriter v1.0.3
   Compiling pkg-config v0.3.9
   Compiling gcc v0.3.51
   Compiling advapi32-sys v0.2.0
   Compiling unicode-segmentation v1.1.0
error: linking with `link.exe` failed: exit code: 1181
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\VC\\Tools\\MSVC\\14.10.25017\\bin\\HostX86\\x86\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\tochecch\\AppData\\Local\\Temp\\cargo-install.abPCagDNmi5f\\release\\build\\advapi32-sys-a27db48c38a94830\\build_script_build-a27db48c38a94830.0.o" "/OUT:C:\\Users\\tochecch\\AppData\\Local\\Temp\\cargo-install.abPCagDNmi5f\\release\\build\\advapi32-sys-a27db48c38a94830\\build_script_build-a27db48c38a94830.exe" "/OPT:REF,ICF" "/DEBUG" "/LIBPATH:C:\\Users\\tochecch\\AppData\\Local\\Temp\\cargo-install.abPCagDNmi5f\\release\\deps" "/LIBPATH:C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\tochecch\\AppData\\Local\\Temp\\cargo-install.abPCagDNmi5f\\release\\deps\\libbuild-cc558114ba27a576.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-0a78323911070f99.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librand-c279a51d66700350.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcollections-d7bf31a4ca1ea637.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_unicode-d367c3ba0db49600.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-2d4bf02140c11dcb.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-add7a84d7e82d084.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-84688accbc86d6b7.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-fe2e68b21f0bdd7a.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc_system-7fc0381594c93f56.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-ea9d77e7c23fe65c.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-91b619d34dd1f5aa.rlib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "shell32.lib" "msvcrt.lib"
  = note: LINK : fatal error LNK1181: cannot open input file 'userenv.lib'


error: aborting due to previous error

error: Could not compile `advapi32-sys`.
Build failed, waiting for other jobs to finish...

Other crates fail at kernel32-sys or others.
I've installed the VS2015 build tools, tried running this in the 2015/17 MSBuild Command Prompt (the one that runs vcvarsall.bat) but I get the same error everywhere.
I've also tried switching between using VS2017's linker and the linker that came with the Build Tools, and also got no luck.
I know the files it needs are installed, but I have no idea how to let cargo start using them.

Sorry if it's a known issue, but the similar threads I could find didn't solve my problem.

@retep998
Copy link
Member

retep998 commented Jul 5, 2017

Your Windows SDK installation is broken and is missing userenv.lib. Please repair your Windows SDK installation, or reinstall it.

@Tomcc
Copy link
Author

Tomcc commented Jul 5, 2017

Thanks but as I said, userenv.lib is definitely in my installation folder - I also repaired it several times but it didn't help.

@DoumanAsh
Copy link

@Tomcc please try to run console with vcvars32.bat (to have only x32 environment)
cargo should definitely work just fine with 2015/2017 build tools, but if you run from console environment you need to ensure to load correct architecture (though wrong arch should not lead to missing lib)

@retep998
Copy link
Member

retep998 commented Jul 5, 2017

@Tomcc If it couldn't find your Windows SDK at all, it would fail on the first system library in the linker invocation advapi32.lib, not userenv.lib. You might see a userenv.lib in your Windows SDK, but you might be looking in a different Windows SDK than the one that is being used, or perhaps the wrong architecture for that Windows SDK. Check what the exact Windows SDK path being used is by looking in your LIB environment variable, or the respective /LIBPATH argument being passed to the linker by rustc, and then double check that userenv.lib is in fact in that specific Windows SDK folder.

Also, another issue I just noticed is that I see the Rust toolchain you're using is x86_64-pc-windows-msvc which is the 64bit toolchain while the linker you're invoking is HostX86\\x86\\link.exe which is the 32bit linker. Please ensure that the VC++ command prompt or vcvars bat file that you are using matches the architecture of your Rust toolchain, otherwise linking will fail.

@DoumanAsh
Copy link

Just to add for 64bit environment you can use vcvars64.bat

@Tomcc
Copy link
Author

Tomcc commented Jul 6, 2017

@retep998 Thanks! I tried with the VS2015 x64 Native Tools Command Prompt, which uses the right version of the linker. I also ran vcvarsall and vcvars64 to make sure.
It didn't work though:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>vcvarsall

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>vcvars64
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>cargo install cargo-update
    Updating registry `https://github.com/rust-lang/crates.io-index`
  Installing cargo-update v1.1.1
   Compiling void v1.0.2
   Compiling lazy_static v0.2.8
   Compiling bitflags v0.9.1
   Compiling regex-syntax v0.4.1
   Compiling quote v0.3.15
   Compiling json v0.11.8
   Compiling ansi_term v0.9.0
   Compiling unicode-segmentation v1.1.0
   Compiling vec_map v0.8.0
   Compiling vcpkg v0.2.2
   Compiling percent-encoding v1.0.0
   Compiling matches v0.1.6
   Compiling gcc v0.3.51
   Compiling serde v1.0.9
   Compiling pkg-config v0.3.9
   Compiling unicode-bidi v0.3.3
   Compiling semver-parser v0.7.0
   Compiling winapi v0.2.8
   Compiling unicode-width v0.1.4
   Compiling unreachable v1.0.0
   Compiling tabwriter v1.0.3
   Compiling thread_local v0.3.4
   Compiling libc v0.2.24
   Compiling winapi-build v0.1.1
   Compiling semver v0.6.0
   Compiling rand v0.3.15
   Compiling memchr v1.0.1
   Compiling aho-corasick v0.6.3
   Compiling advapi32-sys v0.2.0
   Compiling unicode-xid v0.0.4
   Compiling strsim v0.6.0
error: linking with `link.exe` failed: exit code: 1181
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\amd64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\tochecch\\AppData\\Local\\Temp\\cargo-install.zfSmkQtblLRp\\release\\build\\advapi32-sys-a27db48c38a94830\\build_script_build-a27db48c38a94830.0.o" "/OUT:C:\\Users\\tochecch\\AppData\\Local\\Temp\\cargo-install.zfSmkQtblLRp\\release\\build\\advapi32-sys-a27db48c38a94830\\build_script_build-a27db48c38a94830.exe" "/OPT:REF,ICF" "/DEBUG" "/LIBPATH:C:\\Users\\tochecch\\AppData\\Local\\Temp\\cargo-install.zfSmkQtblLRp\\release\\deps" "/LIBPATH:C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\tochecch\\AppData\\Local\\Temp\\cargo-install.zfSmkQtblLRp\\release\\deps\\libbuild-cc558114ba27a576.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-0a78323911070f99.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librand-c279a51d66700350.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcollections-d7bf31a4ca1ea637.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_unicode-d367c3ba0db49600.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-2d4bf02140c11dcb.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-add7a84d7e82d084.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-84688accbc86d6b7.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-fe2e68b21f0bdd7a.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc_system-7fc0381594c93f56.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-ea9d77e7c23fe65c.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-91b619d34dd1f5aa.rlib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "shell32.lib" "msvcrt.lib"
  = note: LINK : fatal error LNK1181: cannot open input file 'userenv.lib'


error: aborting due to previous error

error: Could not compile `advapi32-sys`.
Build failed, waiting for other jobs to finish...

The problem seems to be that my LIB env variable is not set at all, and that there is no /LIBPATH argument for the Windows SDK at all in that command line!
That's something... do you have an example of how it should look like?
I thought it would set itself up automatically... it did at home, and there it works off the normal command line.

Thanks again!

@Tomcc
Copy link
Author

Tomcc commented Jul 6, 2017

Also a suggestion: cargo could warn you if you try to use any link.exe that's not the MSVC linker... I had that issue at home and it made me waste quite a lot of time :)

@retep998
Copy link
Member

retep998 commented Jul 6, 2017

The problem seems to be that my LIB env variable is not set at all, and that there is no /LIBPATH argument for the Windows SDK at all in that command line!

LIB is only set inside a configured environment, such as after you invoke one of the vcvars bat files. It's typically not going to be set when you're in a brand new console. Meanwhile /LIBPATH for the Windows SDK will only be passed by rustc to the linker when you're not inside a configured environment. Either one or the other will be there.

@Tomcc
Copy link
Author

Tomcc commented Jul 6, 2017

Uhm... I tried on my home machine, and funnily enough, if I try to use VS2015 x64 Native Tools Command Prompt I actually get an error that vcvarsall.bat could not be found. And then it works anyway!
On this machine cargo it seems to be able to link on any cmd or even MinGW bash... I'm sure that vcvars* shouldn't be needed. No idea what the difference would be though.
Is there any log/verbose output/anything that can help?

@DoumanAsh
Copy link

I think we need to focus exactly what is your issue.
Is your problem running cargo/rust from VS2015 prompt?

If you get error that vcvarsall.bat is missing, then you definitely isn't going to have needed environment variables.
If you have issues with even prompt it sounds like a problem of your installation.
Did you check that your home machine has this vcvarsall.bat?

You can use tool Everything to quickly index all files. It is portable so you can grab just exe here https://www.voidtools.com/

@Tomcc
Copy link
Author

Tomcc commented Jul 13, 2017

@DoumanAsh I agree, it got a bit confused :)
So, the problem is that cargo and rust cannot link any win32-specific crate from any console.
I've tried in Git's Bash, in cmd, in the VS2015 prompt (as recommended here), I made sure that vcvarsall.bat was run (I have it and it works), and made sure that the right linker was called;
I'm also sure that I have the libraries I need.

Ironically, my home machine runs cargo perfectly through mingw's bash even though I don't have vcvarsall.bat and the VS2015 Native Console doesn't work... so whatever it is, I doubt that vcvarsall.bat is actually needed.

This is the error I get now, which is the same I was getting before:

    Updating registry `https://github.com/rust-lang/crates.io-index`
  Installing cargo-update v1.1.1
   Compiling semver-parser v0.7.0
   Compiling json v0.11.8
   Compiling libc v0.2.26
   Compiling winapi-build v0.1.1
   Compiling winapi v0.2.8
   Compiling void v1.0.2
   Compiling lazy_static v0.2.8
   Compiling utf8-ranges v1.0.0
   Compiling unreachable v1.0.0
   Compiling vcpkg v0.2.2
   Compiling serde v1.0.10
   Compiling thread_local v0.3.4
   Compiling percent-encoding v1.0.0
   Compiling array_tool v0.4.0
   Compiling unicode-xid v0.0.4
   Compiling memchr v1.0.1
   Compiling synom v0.11.3
   Compiling gcc v0.3.51
   Compiling semver v0.6.0
   Compiling aho-corasick v0.6.3
   Compiling regex-syntax v0.4.1
   Compiling vec_map v0.8.0
   Compiling unicode-segmentation v1.1.0
   Compiling ansi_term v0.9.0
   Compiling matches v0.1.6
   Compiling strsim v0.6.0
   Compiling unicode-bidi v0.3.4
   Compiling kernel32-sys v0.2.2
error: linking with `link.exe` failed: exit code: 1181
  |
  = 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\\10\\lib\\10.0.15063.0\\ucrt\\x64" "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.15063.0\\um\\x64" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\tochecch\\AppData\\Local\\Temp\\cargo-install.LWP8drBtUD59\\release\\build\\kernel32-sys-5ee1259db1228dbc\\build_script_build-5ee1259db1228dbc.0.o" "/OUT:C:\\Users\\tochecch\\AppData\\Local\\Temp\\cargo-install.LWP8drBtUD59\\release\\build\\kernel32-sys-5ee1259db1228dbc\\build_script_build-5ee1259db1228dbc.exe" "/OPT:REF,ICF" "/DEBUG" "/LIBPATH:C:\\Users\\tochecch\\AppData\\Local\\Temp\\cargo-install.LWP8drBtUD59\\release\\deps" "/LIBPATH:C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\tochecch\\AppData\\Local\\Temp\\cargo-install.LWP8drBtUD59\\release\\deps\\libbuild-cc558114ba27a576.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-0a78323911070f99.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librand-c279a51d66700350.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcollections-d7bf31a4ca1ea637.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_unicode-d367c3ba0db49600.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-2d4bf02140c11dcb.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-add7a84d7e82d084.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-84688accbc86d6b7.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-fe2e68b21f0bdd7a.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc_system-7fc0381594c93f56.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-ea9d77e7c23fe65c.rlib" "C:\\Users\\tochecch\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-91b619d34dd1f5aa.rlib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "shell32.lib" "msvcrt.lib"
  = note: LINK : fatal error LNK1181: cannot open input file 'userenv.lib'


error: aborting due to previous error

error: Could not compile `kernel32-sys`.
Build failed, waiting for other jobs to finish...

Still no luck... maybe my VS install is corrupted.

@retep998
Copy link
Member

Looking at your linker line I see "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.15063.0\\um\\x64". Can you please take a look in specifically C:\Program Files (x86)\Windows Kits\10\lib\10.0.15063.0\um\x64 and double check that there is a userenv.lib there?

@Tomcc
Copy link
Author

Tomcc commented Jul 14, 2017

So, at home, where it works, I do. I'll check tomorrow at work. Thanks!

@Tomcc
Copy link
Author

Tomcc commented Jul 14, 2017

Ok... so that folder exists, it's full of files, but... there's no userenv.lib there! I should have checked before... that's definitely the problem.
Not Rust related, you can close if you want.
However, do you have any idea of why my Windows SDK might be broken? I tried repairing it using the VS Installer but I had no luck.

EDIT: Leaving this here if anyone had the same issue eventually:

For some reason, on my machine Rust really didn't want to pick the Windows SDK installed by the standalone build tools (which contained userenv.lib); it might have to do with the fact that I had VS2017 installed already.

I managed to get a UserEnv.lib by fiddling more with the Visual Studio Installer. Apparently, in VS2017 you need a few more packages than what I have - just the SDK isn't enough, you also need "Windows 10 SDK (10.0.15063) for Desktop C++"... otherwise you get only SOME of the files. Amazing!
This might still be kinda rust's fault for not preferring 2015's SDK and/or not letting me choose which SDK to use, but I have no idea.

@Tomcc Tomcc closed this as completed Jul 14, 2017
@pravic
Copy link
Contributor

pravic commented Jul 21, 2017

just the SDK isn't enough

@Tomcc Sorry, what did you mean by "just SDK"?

@Tomcc
Copy link
Author

Tomcc commented Jul 23, 2017

@pravic when you install VS2017, if you install each component individually it's a mess.

You have the choice to install Windows 10 SDK (10.0.15063). However, installing only that one isn't enough! You also have to install Windows 10 SDK (10.0.15063) for Desktop C++ x86 and x64 and VC++ 2017 v141 toolset (x86, x64).

Just installing the package called "SDK" is not enough. Actually those 3 probably aren't enough either, but I have another billion packages installed and adding those made it work :)

@MVoz
Copy link

MVoz commented Jul 23, 2017

call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"


    "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" [option]
  or
    "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" [option] store
  or
    "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" [option] [version number]
  or
    "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" [option] store [version number]
where [option] is: x86 | amd64 | arm | x86_amd64 | x86_arm | amd64_x86 | amd64_arm
where [version number] is either the full Windows 10 SDK version number or "8.1" to use the windows 8.1 SDK
:
The store parameter sets environment variables to support
  store (rather than desktop) development.
:
For example:
    "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
    "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_arm store
    "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64 10.0.10240.0
    "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_arm store 10.0.10240.0
    "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 8.1
    "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 store 8.1
:
Please make sure either Visual Studio or C++ Build SKU is installed.

x64 + 10.0.15063
call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64 10.0.15063

@houssemFat-DDF
Copy link

Based on @Tomcc comment.
We need to install other sdk tools for windows 10. Below the list of VS C++ requirements for running the hello word example

image

@JamesChan
Copy link

for my example, maybe the cause is the order of installation for rust and windows SDK. When I repaired SDK, things got!

@hsolg
Copy link

hsolg commented Feb 20, 2020

I installed Rust on a Windows 10 machine with no compilers or SDKs previously installed and I only needed these two components from the Visual Studio Build Tools installer:

  • MSVC v142 - VS 2019 C++ x64/x86 build tools ...
  • Windows 10 SDK (1.0.18362.0)

When I open a command prompt with "Visual Studio 2019" -> "x64 Native Tools Command Prompt" on the start menu, I can successfully build Rust applications with "cargo build".

JakobPapirov added a commit to JakobPapirov/Rosetta_Stone that referenced this issue Jan 8, 2022
A few hours later?! Finally!

I encountered a fairly common windows10 problem with link.exe. Solution was https://gitanswer.com/rustup-link-exe-problem-on-windows-10-rust-338009649 which lead me to rust-lang/rust#43039

Apparently, this can occur when you decide to download specific components yourself instead of downloading the entire Visual Studio (can't find the exact reference).

```error: linker `link.exe` not found
  |
  = note: The system cannot find the file specified. (os error 2)

note: the msvc targets depend on the msvc linker but `link.exe` was not found

note: please ensure that VS 2013, VS 2015, VS 2017 or VS 2019 was installed with the Visual C++ option

error: aborting due to previous error```

* In Visual Studio I needed to download in `Desktop development with C++` MSBuild Tools
* Core: C++ Build Tools core feature
* C++ 2019 Redistributable Update
* C++ core desktop feature

* Optional: MSVC v142 - VS 2019 C++ x64/x86 build tools (latest) <- was the last one I didn't have
* Windows 10 SDK (10.0.16299.0)

Interestingly enough there was never an issue with the missing ```userenv.lib ``` as in the GH issue linked.

I believe that's it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants