Visual Studio can't build due to rc.exe

2019-01-03 08:36发布

I've searched online and couldn't find anything that resembled to my issue.

I created an empty C++ project and added a main.cpp with a return and I can't get it to build. Here is the message I receive :

1>------ Build started: Project: Project1, Configuration: Debug Win32 ------
1>LINK : fatal error LNK1158: cannot run 'rc.exe'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Is there somewhere within VS2012 where I can specify where to find this executable? I have installed the Windows 7 SDK and I have this executable at:

C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin

I come from Code::Blocks and using mingw-gcc without any trouble, but lately I've been needing VS for managed implementations so I hope someone has an idea.

17条回答
我只想做你的唯一
2楼-- · 2019-01-03 09:04

This 'rc.exe' error can occur if the Visual C++ compiler and the Windows 10 SDK versions don't correspond to the same Visual Studio year.

If you have Visual Studio 2017, and you installed Build Tools 2015 without selecting to install its own 2015 Windows SDK (default installation does not install it!), and are trying to use it to compile, you may run into this problem.

In my case, I already had Visual Studio 2017. When I tried to use Build Tools 2015 to compile a python library (or probably any program), this same 'rc.exe' error occurred. I read that the VS2015 14.0 C++ compiler can glitch if it tries to use the Windows 10 SDK from Visual Studio 2017.

I uninstalled Build Tools 2015, and reinstalled it, this time as a custom installation, selecting to install both visual C++ and Windows 10 SDK components. This fixed the issue.

查看更多
我命由我不由天
3楼-- · 2019-01-03 09:07

In my case the error was due to a bad setting in a vcxproj. The vcxproj was from a third party, so I'm not sure how it got in that state.

Specifically, for one of the platform/profile combos, the platform folder was missing from the Windows SDK bin folder:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
 <ExecutablePath>$(VCInstallDir)bin\x86_amd64;$(VCInstallDir)bin;$(WindowsSdkDir)bin\NETFX 4.0 Tools;$(WindowsSdkDir)bin\x86;

is correct, where

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
 <ExecutablePath>$(VCInstallDir)bin\x86_amd64;$(VCInstallDir)bin;$(WindowsSdkDir)bin\NETFX 4.0 Tools;$(WindowsSdkDir)bin;

was incorrect. Might need to scroll to the end of the code boxes to see the difference.

Note also, that for some strange reason $(WindowsSdkDir)bin\x64; did NOT work for me. Tried to figure out why, when rc.exe definitely exists in that folder, but I gave up.

In my opinion, the solutions from previous posters that involve copying rc.exe all over the place are wrong, because your project will not work on anyone else's machine. If you fix up the paths in the project correctly, it should work on any machine with a correct installation of the Windows SDK.

查看更多
可以哭但决不认输i
4楼-- · 2019-01-03 09:08

We hit this issue with our CMake/Visual Studio 2015 builds after also installing VS2017 on the machine. The correct solution in our case is to specify the Window Kit version (8.1) to the Visual Studio Command Prompt - otherwise you get the Windows 10 Kit by default which doesn't include rc.exe in the bin directory.

e.g. Start Menu->Visual Studio 2015->VS2015 x64 Native Tools Command Prompt

%comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64 8.1

Note the 8.1 option on the end

查看更多
我只想做你的唯一
5楼-- · 2019-01-03 09:10

In my case, I had a mix and match error between projects created in VS2015 and VS2017. In my .vcxproj file, there's this section called PropertyGroup Label="Globals">. I had a section for TargetPlatformVersion=10.0.15063.0. When I removed the TargetPlatformVersion, that solved the problem.

Sorry I can't copy and paste the block here, but stackoverflows coding format did not allow that.

查看更多
孤傲高冷的网名
6楼-- · 2019-01-03 09:15

I had the same problem on VS 2013 and was able to fix it by changing the Platform Toolset.

You can find it in project settings, general.

E.g. switching Platform Toolset to VS 2010 will cause VS to use the Windows\v7.0A SDK.

You can check which SDK path is used by adding this to your prebuild event:

echo using SDK $(WindowsSdkDir)
查看更多
Juvenile、少年°
7楼-- · 2019-01-03 09:18

Found this on Google... I would assume that in your case you would copy rc.exe and rcdll.dll to visual studio 2012\vc\bin or wherever you have it installed:

Part 2: FIX LINK : fatal error LNK1158: cannot run ‘rc.exe’

Add this to your PATH environment variables:

C:\Program Files (x86)\Windows Kits\8.0\bin\x86

Copy these files:

rc.exe
rcdll.dll

From

C:\Program Files (x86)\Windows Kits\8.0\bin\x86

To

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin

Or I also found this:
Microsoft left a few things out of their MSVT package. Since no one knows whether they were left out by mistake or for license reasons, no one with MSVC is too interested in giving them out. A few Google searches turn up some tricky sources. Fortunately, Microsoft has finally wised up and solved this problem and many more.

http://msdn.microsoft.com/vstudio/express/support/faq/default.aspx#pricing

http://msdn.microsoft.com/vstudio/express/support/install/

A good amount of MSVT missing files are there but the missing SDK files aren't.

and this:
I had the same problem which I solved by doing this:

  1. Installing the Microsoft .Net Framework 2.0
  2. Adding the path of the .NET Framework files (for me "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727") to Global compiler settings > Programs > Additional Paths within Code::Blocks.

Now I can build and link resource files without errors.

查看更多
登录 后发表回答