LNK1158 cannot run rc.exe x64 Visual Studio

2019-02-21 17:10发布

问题:

I'm trying to compile a simple program in Visual Studio for a 64-bit platform. Upon trying to compile, I get the error: LINK : fatal error LNK1158: cannot run 'rc.exe'

I've been to many discussion threads where it indicates to copy rc.exe and rcdll.dll from the Windows Kits folder to the VC/bin folder. I've done this to no avail. It occurs to me that my version of Visual Studio may just not be looking in the directory I think it's looking for this rc.exe file. Is there a way to identify w/in Visual Studio which directory it's looking for this executable?

(It was suggested that this problem may be a duplicate of the question and answer provided at Cannot compile with VC++/VS2010 targeting x64: LNK1158: cannot run cvtres.exe. However, this does not seem to be the case because, there, the path was getting corrupted by some NV services that were running on the system. I am not having that problem as my full path shows up when I type echo %PATH%. That being said, that link did lead me to the correct solution, given below)

回答1:

The error was indeed where I was placing the rc.exe and rcdll.dll files. Because I'm compiling to a 64-bit platform, Visual Studio is using the 64-bit 'cross-compiler' which does not reside in the $(VSInstallDir)\VC\bin but in the $(VSInstallDir)\VC\bin\x86_amd64 folder.

Thus, the solution to my problem was to copy rc.exe and rcdll.dll from the C:\Program Files (x86)\Windows Kits\8.1\bin\x86 folder to the $(VSInstallDir)\VC\bin\x86_amd64 folder.

Doing that overcame that first error.

However, upon building, a new error popped up: LNK1158: cannot run 'cvtres.exe'. In contrast to my first rc.exe error, this file actually already does reside in the $(VSInstallDir)\VC\bin folder. The problem is that the cross-compiler is looking for it in its own directory. So I just copied that file from the $(VSInstallDir)\VC\bin folder to the $(VSInstallDir)\VC\bin\x86_amd64 folder.

Once I did that, my project built and ran.



回答2:

i encountered this error while compiling a python code in VS2015 windows 10 copied on anaconda3.

rc.exe

rcdll.dll

from

C:\Program Files (x86)\Windows Kits\10\bin\10.0.17134.0\x64

and pasted into visual studio installation folder

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

successfully generated the code.