title: Cannot compile with VC++/VS2010 targeting x64: LNK1158: cannot run cvtres.exe
body: <p>As a C# developer, I recently decided to take a crack at writing some C++ programs, mainly because I found an interesting C++ API I wanted to play around with. I wrote a very simple program a few days ago, compiled it on the x64 target platform, ran it, and everything was just peachy.</p>
  
  <p>However, yesterday I changed some of the code, tried to compile it, but then the linker started to complain:</p>
  
  <p><em>LNK1158: cannot run 'cvtres.exe'</em></p>
  
  <p>As I am quite new to developing C++ programs, I thought I must had made some beginner's mistake. However, after checking all configuration, searching google for several hours, and trying several 'fixes', I'm starting to think this problem might be caused by something more delegate, and the point is: I cannot seem to resolve the issue at all, so I was hoping to get some good feedback here.</p>
  
  <p>First of all, let me list my configuration:</p>
  
  <ul>
  <li>I am running Windows 7 (x64) and am using VS2010 Premium.</li>
  <li>I have created a standard and empty Win32 Console application with only a single .cpp-file inside it that contains the main function. It's not a Hello World program, but not far off.</li>
  <li>Since I have an x64 platform, I'm also using an x64 target-platform configuration. I created this configuration without copying any settings from the Win32 configuration.</li>
  <li>In Project Properties -> VC++ Directories, I left all directories at their defaults (though I did change them a few times to attempt to resolve the issue, without success, so I went back to the defaults).</li>
  </ul>
  
  <p>This last point seems to be crucial, since the VC++ Directory settings determine which compiler and linker are used. At this point, the cross-compiler residing in the <strong>$(VCInstallDir)bin\x86_amd64</strong>-directory is used. Furthermore, all other directories seem to point at x64 versions of all libraries and so on.</p>
  
  <p>When you google this problem, you will find out that the linker used (link.exe) wants to execute cvtres.exe, which it cannot find. This problem seems to occur when cvtres.exe is neither in the same directory as the linker, nor in a directory that is resolved using the PATH-variable.</p>
  
  <p>So I verified this and there is indeed no version of cvtres.exe in <strong>$(VCInstallDir)bin\x86_amd64</strong> (though there are versions of it in the base-directory (<strong>$(VCInstallDir)bin</strong>) and in the 'pure' <strong>$(VCInstallDir)bin\amd64</strong> directory), nor does the PATH-variable contain any listing of a directory that contains a version of cvtres.exe.</p>
  
  <p><strong>-- Attempt #01 - Fix the problem at hand --</strong></p>
  
  <p>As a result, you might conclude that the error is, in fact, a legal failure and I should fix this by either copying a version of cvtres.exe directly in the <strong>$(VCInstallDir)bin\x86_amd64</strong> directory, or edit the PATH-variable as such that it points to usable version of it.</p>
  
  <p>Unfortunately, none of this works.</p>
  
  <p>When I copy cvtres.exe from <strong>$(VCInstallDir)bin</strong> or <strong>$(VCInstallDir)bin\amd64</strong> to <strong>$(VCInstallDir)bin\x86_amd64</strong> and compile, I either get the same message (now referring to the exact location: 'cannot run <strong>$(VCInstallDir)bin\x86_amd64\cvtres.exe</strong>', though it is there) or the linker exits with some unknown error-code (probably because the version of <strong>$(VCInstallDir)bin\amd64</strong> is native x64 unlike the x86 cross-compiler which I have found out to be running in WoW64 mode).</p>
  
  <p>The problem with attempting to edit the PATH-variable such that the linker can find a version cvtres.exe also fails because I don't know with path to refer to (it seems there are many more versions of cvtres.exe kept in various locations, also in the .NET 4.0 SDK directory for example).</p>
  
  <p><strong>-- Attempt #02 - Circumvent the problem by trying a different approach --</strong></p>
  
  <p>Another path that I have taken is to try to use the compiler and linker in the <strong>$(VCInstallDir)bin\amd64</strong> instead of the cross-compiler. After all, I am running a 64-bit machine so I shouldn't need to use the cross-compiler, though Microsoft seems to choose this one by default, regardless of your local configuration/OS.</p>
  
  <p>So I changed the VC++ Directory to point to this location and indeed the problem no longer occurs, but now I got a tracker-problem running the CL.exe instead:</p>
  
  <p><em>TRK0002: [CL.exe] '@[TempFile].rsp': Invalid handle.</em></p>
  
  <p>When I look for this temp-file I cannot find it, but I'm not sure whether it is immediately deleted after compilation 'completed' or it was never present at all. Unfortunately, googling this issue is a dead end also, and <a href="http://connect.microsoft.com/VisualStudio/feedback/details/505682/x64-c-c-projects-cannot-compile" rel="noreferrer">MS Visual Studio 2010 team even recognise this issue but have put it on 'Won't Fix'</a>. In short, compiling natively 64-bit seems to be a known, general problem with VS2010, so I decided to go back to square one on this one, especially since other people having this problem always say 'well you can fix this problem by just using the cross-compiler instead of the native x64 compiler'.</p>
  
  <p>OK, so now I find myself running out of options... And the crazy thing is that it all worked fine just a few days ago and I'm pretty sure I did not change or install anything regarding this project, nor updated Visual Studio or the .NET Framework somehow. I even checked the Windows Updated but can't find any related updates for the last few days.</p>
  
  <p>The only thing I could do, really as a last resort, is to downgrade the whole thing to 32-bit and download the 32-bit version of the API, but I'd really want to avoid this one because it seems to me I should be able to compile and run 64-bit applications on my 64-bit laptop/OS.</p>
  
  <p>So please, any suggestions?</p>
  
  <p><em>Update</em>: According to <a href="http://msdn.microsoft.com/en-us/library/aa448630.aspx" rel="noreferrer">this instruction from MS</a>, the PATH-variable for the linker has to point at the base-directory of the VC++ install. That is the <strong>$(VCInstallDir)bin</strong> I have been talking about. I have tried this, but does not solve the issue. I am wondering what is happening in the background when a VS Build is fired that I don't seem to know of...</p>
  
  <p>@Hans Passant: Thnx for the tip! Process Monitor shows me that link.exe is trying to find cvtres.exe on one of following locations:</p>
  
  <ul>
  <li>$(VCInstallDir)bin\x86_amd64</li>
  <li>$(SourceFileDir)</li>
  <li>C:\Windows\System32\NV</li>
  </ul>
  
  <p>Needless to say, cvtres.exe exists in none of these directories. It's rather strange that <em>only</em> those locations are searched. I would at least expect that <strong>$(VCInstallDir)bin</strong> was searched, since this directory is explicitly listed in both the VC++ Directories and in the PATH-variable (which I editted manually for this purpose). I guess this comes down to findout out why this behaviour is as it is....</p>
  
  <p><em>Update2</em>: Just to put out some extra info, I decided to copy cvtres.exe from the <strong>$(VCInstallDir)bin</strong> to the <strong>$(VCInstallDir)bin\x86_amd64</strong> directory, based on my findings using ProcMon, just to see what was happening then. First of all, as before, Visual Studio tells me the following:</p>
  
  <p><em>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\x64\Microsoft.Cpp.x64.Targets(389,5): error MSB6006: "link.exe" exited with code -1073741515.</em> (The line here just refers to a settings that checks which non-zero exit-codes are acceptable - the actual error-code was returned by link.exe.)</p>
  
  <p>However, in the output Window of ProcMon I can see that cvtres.exe is found and is performing a large amount of work - to completion as it seems, but I am not quite sure about that. Anyway, the error still prevents me from executing the created executable, since it complains a certain referenced library was not found. This is probably due to the fact that the linker did not finish correctly, so in short, it does not resolve my issue here.</p>
  
  <p><em>Update3</em>: Another 'interesting' thing I tried was to just create a new, plain Win32 project with all MS defaults and I didn't even touch the code that is generated for me (a main function returning immediately), just to see at least a single program compile. Suprisingly, I now get the same error as above (link.exe exited with code -1073741515), so now I really start to think something's really wrong with my installation here.</p>
  
  <p>So then I tried to de- and reinstall the VC++ parts of Visual Studio, but to no avail... At this point a full install of Visual Studio is no option since I'm also still in the middle of developing C# projects and I have tons of other add-ins installed that just take too much of my time at the moment to re-install and reconfigure. I might try this in the weekend if nothing has worked out until then.</p>
  
  <p>Instead, I did some research on the error code and I think it has something to do with the fact that link.exe cannot find or access a dependency it requires. I already turned off my VirusScanner just to be safe (doesn't  help), so now I'm downloading the latest Windows SDK (7.1) to see if that does anything. If that doesn't help, I'm guess it is either a terrible bug, or my installation is really screwed up somewhere and I might have to reinstall VS and all it's stuff...</p>
  
  <p>Thanks for the suggestions anyway!</p>