visual-studio 链接:致命错误 LNK1104:无法打开文件“D:\...\MyProj.exe”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3906404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 12:35:34  来源:igfitidea点击:

LINK : fatal error LNK1104: cannot open file 'D:\...\MyProj.exe'

visual-studiovisual-studio-2010lockingexecutable

提问by Jonathan

Using Visual Studio 2010, when I build + run my application in short intervals I often get the following error. If I just wait a minute or two and try again it works fine. Unlockerclaims no handle is locking the executable file.
How can I discover what's locking it?
If it's Visual Studio itself, what should I do to make it stop? or alternatively to release the file?

使用 Visual Studio 2010,当我在短时间内构建 + 运行我的应用程序时,我经常收到以下错误。如果我等一两分钟再试一次,它工作正常。Unlocker声称没有句柄正在锁定可执行文件。
我怎样才能发现是什么锁定了它?
如果是 Visual Studio 本身,我应该怎么做才能让它停止?或者释放文件?

1>------ Build started: Project: MyProj, Configuration: Release Win32 ------
...
1>InitializeBuildStatus:
1>  Creating "Release\MyProj.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1>  All outputs are up-to-date.
1>  SomeFile1.cpp
1>ResourceCompile:
1>  All outputs are up-to-date.
1>LINK : fatal error LNK1104: cannot open file 'D:\...\MyProj.exe'
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.94
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

采纳答案by user963228

Had this issue after a reinstall today. Make sure the Application Experience service is started and not set to disabled. If its set to manual, I believe VS will start it.

今天重装后出现这个问题。确保应用程序体验服务已启动且未设置为禁用。如果它设置为手动,我相信 VS 会启动它。

回答by standrejo

I'm aware this is quite old but I just had the same problem with Visual Studio 2010 all patched up so others may still run into this.

我知道这已经很老了,但我刚刚在 Visual Studio 2010 上遇到了同样的问题,所有补丁都被修补了,所以其他人可能仍然会遇到这个问题。

Adding my project path to "Exluded Items" in my AVG anti-virus settings appears to have fixed the problem for me.

在我的 AVG 防病毒设置中将我的项目路径添加到“排除的项目”似乎已经解决了我的问题。

Try disabling any anti-virus/resident shield and see if it fixes the problem. If so, add your project path to excluded directories in your AV config.

尝试禁用任何防病毒/驻留盾牌,看看它是否能解决问题。如果是这样,请将您的项目路径添加到您的 AV 配置中的排除目录。

回答by C Johnson

You probably had a stray build process that was locking the executable, and it (the stray process) didn't get cleaned up. In that case, shut down visual studio, open up process explorer, and nuke every process you can find that is related to visual studio. Then open up visual studio again and try rebuilding your project.

您可能有一个锁定可执行文件的杂散构建过程,并且它(杂散进程)没有得到清理。在这种情况下,请关闭 Visual Studio,打开流程资源管理器,然后取消您能找到的与 Visual Studio 相关的每个流程。然后再次打开 Visual Studio 并尝试重建您的项目。

回答by Ilya Smagin

the file can be locked because it is being run now. Try killing the process with a task manager.

该文件可以被锁定,因为它现在正在运行。尝试使用任务管理器终止进程。

回答by Balaji

You might have not closed the the output. Close the output, clean and rebuild the file. You might be able to run the file now.

您可能没有关闭输出。关闭输出,清理并重建文件。您现在也许可以运行该文件。

回答by Tebe

Like Jonathan said, yes, renaming can help to work around this problem. But ,e.g. I was forced to rename target executable many times, it's some tedious and not good.

正如乔纳森所说,是的,重命名可以帮助解决这个问题。但是,例如我被迫多次重命名目标可执行文件,这有些乏味而且不好。

The problem lies there that when you run your project and later get an error that you can't build your project - it's so because this executable (your project) is still runnning (you can check it via task manager.) If you just rename target build, some time later you will get the same error with new name too and if you open a task manager, you will see that you rubbish system with your not finished projects.

问题在于,当你运行你的项目然后得到一个错误你不能构建你的项目 - 这是因为这个可执行文件(你的项目)仍在运行(你可以通过任务管理器检查它。)如果你只是重命名目标构建,一段时间后,您也会收到与新名称相同的错误,如果您打开任务管理器,您将看到未完成项目的垃圾系统。

Visual studio for making a new build need to remove previous executable and create new instead of old, it can't do it while executable is still runinng. So, if you want to make a new build, process of old executable has to be closed! (it's strange that visual studio doesn't close it by itself and yes, it looks like some buggy behaviour).

用于进行新构建的 Visual Studio 需要删除以前的可执行文件并创建新的而不是旧的,当可执行文件仍在运行时它无法执行此操作。因此,如果要进行新构建,则必须关闭旧可执行文件的进程!(奇怪的是,visual studio 不会自行关闭它,是的,它看起来像一些错误的行为)。

enter image description here

在此处输入图片说明

It's some tedious to do it manually, so you may just a bat file and just click it when you have such problem:

手动完成有些乏味,所以您可能只是一个bat文件,遇到此类问题时只需单击它:

taskkill /f /im name_of_target_executable.exe

it works for me at least. Like a guess - I don't close my program properly in C++, so may be it's normal for visual studio to hold it running.

它至少对我有用。就像猜测一样 - 我没有在 C++ 中正确关闭我的程序,所以 Visual Studio 让它运行可能是正常的。

ADDITION:There is a great chance to be so , because of not finished application. Check whether you called PostQuitMessage in the end, in order to give know Windows that you are done.

ADDITION:很有可能是这样,因为还没有完成申请。检查您是否最终调用了 PostQuitMessage,以便让 Windows 知道您已完成。

回答by Jonathan

I've concluded this is some kind of Visual Studio bug. Perhaps C Johnson is right - perhaps the build process keeps the file locked.

我已经得出结论,这是某种 Visual Studio 错误。也许 C Johnson 是对的——也许构建过程会锁定文件。

I do have a workaround which works - each time this happens - I change the Target Name of the executable under the Project's properties (right click the project, then Properties\Configuration Properties\General\Target Name).

我确实有一个可行的解决方法 - 每次发生这种情况时 - 我更改项目属性下的可执行文件的目标名称(右键单击项目,然后单击 Properties\Configuration Properties\General\Target Name)。

In this fashion VS creates a new executable and the problem is worked around. Every few times I do this I return to the original name, thus cycling through ~3 names.

以这种方式 VS 创建一个新的可执行文件,问题就解决了。每隔几次,我就会回到原来的名字,从而循环使用 ~3 个名字。

If someone will find the reason for this and a solution, please do answer and I may move the answer to yours, as mine is a workaround.

如果有人会找到原因和解决方案,请回答,我可能会将答案移至您的答案,因为我的是一种解决方法。

回答by Peeter

I had the same problem, however using Codeblocks. Because of this problem i quited programming because everytime i just wanted to throw my computer out of the window.

我有同样的问题,但是使用代码块。由于这个问题,我停止了编程,因为每次我只想把我的电脑扔出窗外。

I want to thank user963228 whos answer is really a solution to that. You have to put Application Experience on Manual startup(you can do it by searching services in windows 7 start menu, and then find Application Experience and click properties).

我要感谢 user963228,他的回答确实是一个解决方案。您必须将应用程序体验设置为手动启动(您可以通过在 Windows 7 开始菜单中搜索服务,然后找到应用程序体验并单击属性来实现)。

This problem happens when people want to tweak theyr windows 7 machine, and they decide to disable some pointless services, so they google some tweaking guide and most of those guides say that Application Experience is safe to disable.

当人们想要调整他们的 Windows 7 机器并且他们决定禁用一些毫无意义的服务时,就会发生这个问题,所以他们在谷歌上搜索了一些调整指南,其中大部分指南都说应用程序体验可以安全地禁用。

I think this problem should be linked to windows 7 problem not VS problem and it should be more visible - it took me long time to find this solution.

我认为这个问题应该与 windows 7 问题有关,而不是 VS 问题,它应该更明显 - 我花了很长时间才找到这个解决方案。

Thanks again!

再次感谢!

回答by SJoshi

Just to add another solution to the list, what I've found is that Visual Studio (2012 in my case) occasionally locks files under different processes.

只是在列表中添加另一个解决方案,我发现 Visual Studio(在我的例子中是 2012)偶尔会锁定不同进程下的文件。

So, on a crash, devenv.exe might still be running and holding onto the file(s). Alternatively (as I just discovered), vstestrunner or vstestdiscovery might be holding onto the file as well.

因此,在崩溃时,devenv.exe 可能仍在运行并保留文件。或者(正如我刚刚发现的),vstestrunner 或 vstestdiscovery 也可能会保留该文件。

Kill all those processes and it might fix up the issue.

杀死所有这些进程,它可能会解决问题。

回答by blairh

I have just run into the same issue with VS2013, creating device drivers in C++ , and none of the above seemed to fix the issue. However, I have just discovered that in my case the issue appears to have been VMWare-related.

我刚刚在 VS2013 中遇到了同样的问题,在 C++ 中创建了设备驱动程序,但以上似乎都没有解决这个问题。但是,我刚刚发现,就我而言,问题似乎与 VMWare 相关。

I was running a VMWare workstation client with a shared folder defined on the VM on my entire C: drive. When I disabled the shared folders on the VM Settings, VS2013 was able to happily build my .exe files.

我正在运行一个 VMWare 工作站客户端,在我的整个 C: 驱动器上的 VM 上定义了一个共享文件夹。当我在 VM 设置中禁用共享文件夹时,VS2013 能够愉快地构建我的 .exe 文件。

My new process is:

我的新流程是:

1) Disable the shared folder on the vm (VM Settings | Options | Shared Folders - and uncheck the checkbox) 2) Run the build on the host PC 3) RE-enable the shared folder (and proceed from there)

1) 禁用虚拟机上的共享文件夹(VM 设置 | 选项 | 共享文件夹 - 并取消选中复选框)2)在主机 PC 上运行构建 3)重新启用共享文件夹(并从那里继续)

Hopefully this might help someone else.

希望这可以帮助其他人。

(BTW, the errors you receive are that the .exe (or other files) are locked or require Administrator permission, but that is a red herring - It seems to me that the VMWare share is causing those files to appear as locked.)

(顺便说一句,您收到的错误是 .exe(或其他文件)被锁定或需要管理员权限,但这是一个红鲱鱼 - 在我看来,VMWare 共享导致这些文件显示为锁定。)