无法使用面向 x64 的 VC++/VS2010 进行编译:LNK1158:无法运行 cvtres.exe [英] Cannot compile with VC++/VS2010 targeting x64: LNK1158: cannot run cvtres.exe

查看:87
本文介绍了无法使用面向 x64 的 VC++/VS2010 进行编译:LNK1158:无法运行 cvtres.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一名 C# 开发人员,我最近决定尝试编写一些 C++ 程序,主要是因为我发现了一个有趣的 C++ API,我想尝试一下.前几天写了一个很简单的程序,在x64目标平台上编译,运行,一切都刚刚好.

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.

然而,昨天我改变了一些代码,试图编译它,但随后链接器开始抱怨:

However, yesterday I changed some of the code, tried to compile it, but then the linker started to complain:

LNK1158:无法运行cvtres.exe"

由于我对开发 C++ 程序还很陌生,我想我一定犯了一些初学者的错误.但是,在检查了所有配置,在 google 上搜索了几个小时并尝试了几次修复"之后,我开始认为这个问题可能是由更多委托引起的,重点是:我似乎根本无法解决问题,所以我希望能在这里得到一些好的反馈.

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.

首先,让我列出我的配置:

First of all, let me list my configuration:

  • 我运行的是 Windows 7 (x64) 并使用 VS2010 Premium.
  • 我创建了一个标准的空 Win32 控制台应用程序,其中只有一个包含主函数的 .cpp 文件.这不是一个 Hello World 程序,但也不远了.
  • 因为我有一个 x64 平台,所以我也使用 x64 目标平台配置.我创建此配置时没有从 Win32 配置中复制任何设置.
  • 在项目属性 -> VC++ 目录中,我将所有目录保留为默认值(尽管我确实更改了几次以尝试解决问题,但没有成功,所以我回到了默认值).

最后一点似乎很关键,因为 VC++ 目录设置决定了使用哪个编译器和链接器.此时,将使用位于 $(VCInstallDir)binx86_amd64 目录中的交叉编译器.此外,所有其他目录似乎都指向所有库的 x64 版本等等.

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 $(VCInstallDir)binx86_amd64-directory is used. Furthermore, all other directories seem to point at x64 versions of all libraries and so on.

当你google这个问题时,你会发现使用的链接器(link.exe)想要执行cvtres.exe,它找不到.当 cvtres.exe 既不在与链接器相同的目录中,也不在使用 PATH 变量解析的目录中时,似乎会发生此问题.

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.

所以我验证了这一点,$(VCInstallDir)binx86_amd64 中确实没有 cvtres.exe 的版本(尽管在基目录中有它的版本 ($(VCInstallDir)bin) 和纯"$(VCInstallDir)binamd64 目录中),PATH 变量也不包含任何包含 cvtres 版本的目录列表.exe.

So I verified this and there is indeed no version of cvtres.exe in $(VCInstallDir)binx86_amd64 (though there are versions of it in the base-directory ($(VCInstallDir)bin) and in the 'pure' $(VCInstallDir)binamd64 directory), nor does the PATH-variable contain any listing of a directory that contains a version of cvtres.exe.

-- 尝试 #01 - 解决手头的问题 --

因此,您可能会得出结论,该错误实际上是一个法律错误,我应该通过直接在 $(VCInstallDir)binx86_amd64 中复制一个 cvtres.exe 版本来解决此问题strong> 目录,或编辑 PATH 变量,使其指向可用版本.

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 $(VCInstallDir)binx86_amd64 directory, or edit the PATH-variable as such that it points to usable version of it.

不幸的是,这些都不起作用.

Unfortunately, none of this works.

当我将 cvtres.exe 从 $(VCInstallDir)bin$(VCInstallDir)binamd64 复制到 $(VCInstallDir)binx86_amd64 时strong> 并编译,我要么得到相同的消息(现在指的是确切位置:'cannot run $(VCInstallDir)binx86_amd64cvtres.exe',尽管它在那里)或链接器退出时会出现一些未知的错误代码(可能是因为 $(VCInstallDir)binamd64 的版本是原生 x64,与我发现在 WoW64 模式下运行的 x86 交叉编译器不同).

When I copy cvtres.exe from $(VCInstallDir)bin or $(VCInstallDir)binamd64 to $(VCInstallDir)binx86_amd64 and compile, I either get the same message (now referring to the exact location: 'cannot run $(VCInstallDir)binx86_amd64cvtres.exe', though it is there) or the linker exits with some unknown error-code (probably because the version of $(VCInstallDir)binamd64 is native x64 unlike the x86 cross-compiler which I have found out to be running in WoW64 mode).

尝试编辑 PATH 变量以便链接器可以找到版本 cvtres.exe 的问题也失败了,因为我不知道要引用的路径(似乎还有更多版本的 cvtres.exe 保留在不同的位置,例如也在 .NET 4.0 SDK 目录中).

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).

-- 尝试 #02 - 通过尝试不同的方法来解决问题-

我采用的另一条路径是尝试使用 $(VCInstallDir)binamd64 中的编译器和链接器,而不是交叉编译器.毕竟,我运行的是 64 位机器,所以我不需要使用交叉编译器,尽管微软似乎默认选择了这个,不管你的本地配置/操作系统如何.

Another path that I have taken is to try to use the compiler and linker in the $(VCInstallDir)binamd64 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.

所以我将 VC++ 目录更改为指向这个位置,确实问题不再发生,但现在我在运行 CL.exe 时遇到了跟踪器问题:

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:

TRK0002:[CL.exe] '@[TempFile].rsp':句柄无效.

当我查找这个临时文件时,我找不到它,但我不确定它是在编译完成"后立即删除还是根本不存在.不幸的是,谷歌搜索这个问题也是一个死胡同,MS Visual Studio 2010 团队甚至认识到这个问题,但已将其置于无法修复".简而言之,本地编译 64 位似乎是 VS2010 的一个已知的普遍问题,所以我决定回到这个问题上的第一个问题,特别是因为其他有这个问题的人总是说'好吧,你可以通过以下方式解决这个问题使用交叉编译器而不是本机 x64 编译器'.

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 MS Visual Studio 2010 team even recognise this issue but have put it on 'Won't Fix'. 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'.

好的,所以现在我发现自己的选择不多了......而且疯狂的是,几天前一切都很好,我很确定我没有更改或安装任何关于这个项目的东西,也没有以某种方式更新了 Visual Studio 或 .NET Framework.我什至检查了 Windows Updated,但在过去几天找不到任何相关更新.

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.

我唯一能做的,真的作为最后的手段,就是将整个东西降级到 32 位并下载 API 的 32 位版本,但我真的想避免这个,因为它似乎对我来说,我应该能够在我的 64 位笔记本电脑/操作系统上编译和运行 64 位应用程序.

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.

请问,有什么建议吗?

更新:根据微软的这条说明,链接器的 PATH 变量必须指向 VC++ 安装的基目录.这就是我一直在谈论的 $(VCInstallDir)bin.我试过这个,但没有解决问题.我想知道当我似乎不知道的 VS Build 被触发时,后台发生了什么......

Update: According to this instruction from MS, the PATH-variable for the linker has to point at the base-directory of the VC++ install. That is the $(VCInstallDir)bin 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...

@Hans Passant:谢谢小费!进程监视器向我显示 link.exe 正在尝试在以下位置之一查找 cvtres.exe:

@Hans Passant: Thnx for the tip! Process Monitor shows me that link.exe is trying to find cvtres.exe on one of following locations:

  • $(VCInstallDir)binx86_amd64
  • $(SourceFileDir)
  • C:WindowsSystem32NV

不用说,cvtres.exe 不存在于这些目录中.很奇怪搜索那些位置.我至少希望 $(VCInstallDir)bin 被搜索,因为这个目录在 VC++ 目录和 PATH 变量(我为此手动编辑)中明确列出.我想这归结为找出这种行为的原因......

Needless to say, cvtres.exe exists in none of these directories. It's rather strange that only those locations are searched. I would at least expect that $(VCInstallDir)bin 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....

Update2:为了提供一些额外的信息,我决定将 cvtres.exe 从 $(VCInstallDir)bin 复制到 $(VCInstallDir)binx86_amd64 目录,基于我使用 ProcMon 的发现,只是为了看看当时发生了什么.首先,和以前一样,Visual Studio 告诉我以下内容:

Update2: Just to put out some extra info, I decided to copy cvtres.exe from the $(VCInstallDir)bin to the $(VCInstallDir)binx86_amd64 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:

C:Program Files (x86)MSBuildMicrosoft.Cppv4.0Platformsx64Microsoft.Cpp.x64.Targets(389,5):错误 MSB6006:link.exe"退出代码 -1073741515.(这里的行只是指检查哪些非零退出代码是可接受的设置 - 实际错误代码由 link.exe 返回.)

C:Program Files (x86)MSBuildMicrosoft.Cppv4.0Platformsx64Microsoft.Cpp.x64.Targets(389,5): error MSB6006: "link.exe" exited with code -1073741515. (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.)

但是,在 ProcMon 的输出窗口中,我可以看到找到了 cvtres.exe 并且正在执行大量工作 - 看起来已经完成,但我不太确定.无论如何,该错误仍然阻止我执行创建的可执行文件,因为它抱怨找不到某个引用的库.这可能是因为链接器没有正确完成,所以简而言之,它没有解决我的问题.

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.

Update3:我尝试的另一个有趣"的事情是创建一个新的、普通的 Win32 项目,其中包含所有 MS 默认值,我什至没有接触为我生成的代码(一个主要的函数立即返回),只是为了看到至少一个程序编译.令人惊讶的是,我现在遇到了与上述相同的错误(link.exe 以代码 -1073741515 退出),所以现在我真的开始认为我在这里的安装确实有问题.

Update3: 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.

然后我尝试卸载并重新安装 Visual Studio 的 VC++ 部分,但无济于事......此时完全安装 Visual Studio 是没有选择的,因为我还在开发 C#项目,我安装了大量其他加载项,目前我花了太多时间重新安装和重新配置.如果在那之前没有任何进展,我可能会在周末尝试这个.

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.

相反,我对错误代码进行了一些研究,我认为这与 link.exe 无法找到或访问它所需的依赖项有关.为了安全起见,我已经关闭了 VirusScanner(没有帮助),所以现在我正在下载最新的 Windows SDK (7.1) 以查看是否有任何作用.如果这没有帮助,我想这要么是一个可怕的错误,要么我的安装在某个地方真的搞砸了,我可能不得不重新安装 VS 和所有这些东西...

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...

还是谢谢你的建议!

推荐答案

C:WindowsSystem32NV 路径可能指向正在讨论的问题 这里此处.

The C:WindowsSystem32NV path could point to a problem that is discussed here and here.

似乎某些可以切换图形模式(集成/离散)的 NVIDIA 驱动程序在某些情况下可能会损坏系统路径(例如系统路径上的 Intel 无线路径).

It seems some NVIDIA drivers that can switch graphics modes (integrated/discrete) can corrupt the system path in certain situations (e.g. with Intel Wireless paths on the system path).

禁用 NV 服务可能会解决您的问题.

Disabling the NV Services service may solve your problem.

这篇关于无法使用面向 x64 的 VC++/VS2010 进行编译:LNK1158:无法运行 cvtres.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆