Linking with 'link.exe' failed: exit code: 1171

Hello all,

I have just started using rust (windows 8.1). I downloaded and installed the Build Tools for Visual Studio 2019 and during installation I selected the C++ tools.

I tried this code

fn main()
{
println!("Hello, world!");
}

After using command rustc main.rs

Got the following error:

error: linking with 'link.exe' failed exit code: 1171

Note: fatal error LNK1171: unable to load mspdbcore.dll <error code 126>

What am I doing wrong?

probably it uses wrong linker (32 bit when building 64bit target and vice versa)

No idea how you setup your enviornment, but you must make sure that you load correct environment when it comes to MSVC.
MS cannot make proper build tools sadly so you need to make sure that C++ tools match Rust's target

If you use console like me(powershell) here is simple script to load environment via vswhere

1 Like

Thanks DoumanAsh for replying. Yes, you have a point. Great!

I am new to this all this Powershell setup as well, so I have to run these command on Windows Powershell? Can you please guide me a little how to actually run this all? Sorry for bothering you again.

@hina_z If you're not familiar with powershell then other option would be to use Developer Command Prompt VS which will be available when you install Visual Studio
You need to find vswhere.exe and add it's directory to environment variable PATH
In my case it is located in C:\Program Files (x86)\Microsoft Visual Studio\Installer\

For 64bit target arch should be amd64

But if you're not very well familiar with powershell, it would be also worth to consider how did you run compilation initially?
Did you use cmd?
Did you use IDE?

1 Like

@DoumanAsh Thanks!! Yes, I use cmd for all compilation and installing Rust. and Yes you are right vswhere.exe file is located in the folder you have mentioned.

@DoumanAsh Its still showing the same error, even after adding vswhere.exe location to environmental variable PATH. Anyways, thanks. I am still clueless, rustc --version, rustup, rustup --version, cargo --version, all commands are working fine.

Can you try to compile using a developer command prompt and see if you get the same error?

Check using rustup toolchain list which toolchain is marked as default.
If it is stable-x86_64-pc-windows-msvc when you need 64bit environment using amd64
Otherwise it is something like i686-pc-windows-msvc which means you need 32 bit.

And yeah as alternative you can try Developer Command Prompt find it via windows menu

1 Like

@cfsamson. Yes I am still getting the same error. rustc --version is also working fine. Attaching screenshot, anything you can suggest?

It says:
Note: fatal error LNK1171: unable to load mspdbcore.dll <error code 126>

@DoumanAsh . It's stable-x86_64-pc-windows-msvc. Tried on Developer Command Prompt as well, still getting the same error. What's this fatal error LNK1171: unable to load mspdbcore.dll <error code 126> means? Can I install it again by using some other version of VS Studio? Any suggestion.

Thanks.

Ok, this is very strange.
I would first suggest to try to use cargo instead of rustc directly

You can also check that correct link is setup in your PATH by using powershell command:
Get-Command link | Select-Object -ExpandProperty Definition

For 64bit linker it should return:
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX64\x64\link.exe

1 Like

I would follow, the advice from @DoumanAsh first.

Personally, before I'd dig too deep into finding the root cause for this, I would consider uninstalling and re-installing the build tools and make sure to do a reboot (make sure that rustup is installed on C: as well, I assume that's the case but just saw you switched to E: in one of the examples above, and that could possibly cause issues when resolving paths).

I've installed rust on at least 6 different Windows PC's and never had an issue like this (granted, none were Win 8.1) so this should just work.

1 Like

@DoumanAsh @cfsamson

Thanks alot! Finally, its done. Reinstalling the whole setup again and defining the environmental variable path works. Now both cargo and rustc commands are working. All credit goes to you guys. Now comes the most toughest part, to learn RUST!!!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.