C++ VC++ 致命错误 LNK1168:无法打开 filename.exe 进行写入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12124146/
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-08-27 15:54:43  来源:igfitidea点击:

VC++ fatal error LNK1168: cannot open filename.exe for writing

c++windowsvisual-c++

提问by gogiii

suddenly my visual studio express 2010 c++ stopped rebuilding my project.
When I first hit F7 the project builds and runs fine (heck, it's a hello world example).
Then I make some changes and hit F7 again, then I get:
1>LINK : fatal error LNK1168: cannot open C:\Users\username\Documents\Visual Studio 2010\Projects\console\Debug\console.exe for writing

Now the funny thing comes:

突然我的visual studio express 2010 c++ 停止重建我的项目。
当我第一次按下 F7 时,项目构建并运行良好(见鬼,这是一个 hello world 示例)。
然后我做了一些更改并再次点击 F7,然后我得到:
1>LINK : fatal error LNK1168: cannot open C:\Users\username\Documents\Visual Studio 2010\Projects\console\Debug\console.exe for write

现在有趣的事情来了:

  1. the app is not running and it's not shown in task manager.
  2. going into the project directory and trying to remove it with hands comes with success but the file APPEARS AGAIN FROM NOWHERE o_O
  3. the system restore is disabled
  4. i also tried to take the ownership of the whole damn drive
  5. each time I delete the file it recreates itself again but sometimes it stops doing that
  6. if delete the file (and it recreates after that) and then I start sysinternals procmon then the file will dissapear.
  7. if I start procmon before - then the file keeps appearing after delete like always
  1. 该应用程序未运行且未显示在任务管理器中。
  2. 进入项目目录并尝试用手将其删除会成功,但文件再次从无处出现 o_O
  3. 系统还原被禁用
  4. 我还试图获得整个该死的驱动器的所有权
  5. 每次我删除文件时,它都会重新创建自己,但有时它会停止这样做
  6. 如果删除该文件(并在此之后重新创建)然后我启动 sysinternals procmon 那么该文件将消失。
  7. 如果我之前启动 procmon - 那么文件会像往常一样在删除后继续出现

OS: W7 SP1 64-bit, with latest updates
any ideas, please? google didn't help me :(

操作系统:W7 SP1 64 位,有最新更新有
什么想法吗?谷歌没有帮助我:(

采纳答案by Software_Designer

Enable “Application Experience” service. Launch a console window and type net start AeLookupSvc

启用“应用体验”服务。启动控制台窗口并键入net start AeLookupSvc

回答by CodeMed

The problem is probably that you forgot to close the program and that you instead have the program running in the background.

问题可能是您忘记关闭程序,而是让程序在后台运行。

Find the console window where the exe file program is running, and close it by clicking the X in the upper right corner. Then try to recompile the program. In my case this solved the problem.

找到运行exe文件程序的控制台窗口,点击右上角的X关闭它。然后尝试重新编译程序。就我而言,这解决了问题。

I know this posting is old, but I am answering for the other people like me who find this through the search engines.

我知道这个帖子很旧,但我正在为像我这样通过搜索引擎找到这个帖子的其他人回答。

回答by Aleksei Mialkin

Restarting Visual Studio solved the problem for me.

重新启动 Visual Studio 为我解决了这个问题。

回答by Amal K

I've encountered this problem when the build is abruptly closed before it is loaded. No process would show up in the Task Manager, but if you navigate to the executable generated in the project folder and try to delete it, Windows claims that the application is in use. (If not, just delete the file and rebuild, which generates a new executable) In Windows(Visual Studio 2019), the file is located in this directory by default:

当构建在加载之前突然关闭时,我遇到了这个问题。任务管理器中不会显示任何进程,但如果您导航到项目文件夹中生成的可执行文件并尝试删除它,Windows 会声称该应用程序正在使用中。(如果没有,只需删除文件并重建,这会生成一个新的可执行文件)在 Windows(Visual Studio 2019)中,该文件默认位于此目录中:

%USERPROFILE%\source\repos\ProjectFolderName\Debug

To end the allegedly running process, open the command prompt and type in the following command:

要结束据称正在运行的进程,请打开命令提示符并输入以下命令:

taskkill /F /IM [ApplicationName.exe]

This forces any running instance to be terminated. Rebuild and execute!

这会强制终止任何正在运行的实例。重建并执行!

回答by Hau Le

In my case, cleaning and rebuilding the project resolved the problem.

就我而言,清理和重建项目解决了问题。

回答by Sparsh Jain

well, I actually just saved and closed the project and restarted VS Express 2013 in windows 8 and that sorted my problem.

好吧,我实际上只是保存并关闭了项目,然后在 Windows 8 中重新启动了 VS Express 2013,这解决了我的问题。

回答by Laurie Stearn

This can also be a problem from the improper use of functions like FindNextFile when a FindClose is never executed. The process of the built file is terminated, and the build itself can be deleted, but LNK1168 will prevent a rebuild because of the open handle. This can create a handle leak in Explorer which can be addressed by terminating and restarting Explorer, but in many cases an immediate reboot is necessary.

这也可能是在从未执行 FindClose 时不当使用 FindNextFile 等函数造成的问题。构建文件的进程终止,构建本身可以被删除,但 LNK1168 会因为打开句柄而阻止重建。这可能会在 Explorer 中造成句柄泄漏,这可以通过终止并重新启动 Explorer 来解决,但在许多情况下,需要立即重新启动。

回答by tw1tch01

I know this is an old question but thought I'd share how I resolved the issue.

我知道这是一个老问题,但我想我会分享我如何解决这个问题。

If you're using Visual Studio and this error occurs, you can try to attach to process (CTRL+ALT+P) and find the "(program).exe" process. When you try to attach to it, an error will display stating that it failed to attach which removes the process from "running" (even though it's not...) You'll also be able to delete the (program).exe from your Debug folder.

如果您使用的是 Visual Studio 并且发生此错误,您可以尝试附加到进程 (CTRL+ALT+P) 并找到“(program).exe”进程。当您尝试附加到它时,将显示一个错误,指出它无法附加,这会从“运行”中删除该进程(即使它不是......)您还可以从中删除(程序).exe您的调试文件夹。

Hope this helps someone! :)

希望这可以帮助某人!:)

回答by Jason

I also had this same issue. My console window was no longer open, but I was able to see my application running by going to processes within task manager. The process name was the name of my application. Once I ended the process I was able to build and compile my code with no issues.

我也有同样的问题。我的控制台窗口不再打开,但我能够通过转到任务管理器中的进程来看到我的应用程序正在运行。进程名称是我的应用程序的名称。一旦我结束了这个过程,我就可以毫无问题地构建和编译我的代码。

回答by chosen

Start your program as an administrator. The program can't rewrite your files cause your files are in a protected location on your hard drive.

以管理员身份启动您的程序。该程序无法重写您的文件,因为您的文件位于硬盘驱动器上的受保护位置。