C语言 ld.exe:无法打开输出文件...:权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7655471/
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
ld.exe: cannot open output file ... : Permission denied
提问by gzzzur
I recently installed CodeBlocks with mingw32 on Windows 7 Ultimate 32bit in order to dust off my c skills, but this problem has me somewhat stumped.
我最近在 Windows 7 Ultimate 32bit 上安装了带有 mingw32 的 CodeBlocks,以磨练我的 c 技能,但是这个问题让我有些难倒。
I decided to fire off a short Fibonacci generator to make sure my setup was working, but I ran into a hurdle.
我决定启动一个短的斐波那契发生器以确保我的设置正常工作,但我遇到了一个障碍。
The program compiles, links and whatnot like a charm and I get a corresponding executable which runs as expected.
程序编译、链接和诸如此类的东西,我得到了一个按预期运行的相应可执行文件。
The problems occur if I try to compile again, then I get the following:
如果我再次尝试编译会出现问题,然后我得到以下信息:
c:/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../../mingw32/bin/ld.exe: cannot open output file bin\Debug\Fibonacci.exe: Permission denied
I can't even edit the permissions of the generated executable.
我什至无法编辑生成的可执行文件的权限。
I've checked the usual suspects:
我检查了通常的嫌疑人:
- Executable is verily not running.
- Path to executable is read/writable to mingw32 (otherwise it wouldn't be able to build in the first place)
- I'm not running cygwin in any shape or form.
- 可执行文件确实没有运行。
- 可执行文件的路径对 mingw32 是可读/可写的(否则它首先无法构建)
- 我没有以任何形式运行 cygwin。
And now for the funny bit: Usually after a few minutes, any executables generated by mingw32 which are displaying this Access Denied behaviour will automatically vanish without any intervention from me.
现在有趣的是:通常几分钟后,由 mingw32 生成的任何显示此拒绝访问行为的可执行文件都将自动消失,而无需我的任何干预。
I've googled this somewhat, but most of the other results were either vague or inapplicable.
我在谷歌上搜索了一些,但大多数其他结果要么含糊不清,要么不适用。
I wonder whether there is some Windows 7 security setting playing havoc with my .exe's, but I'm not that knowledgeable about Win 7 as to know where to begin searching.
我想知道是否有一些 Windows 7 安全设置对我的 .exe 造成了严重破坏,但我对 Win 7 不太了解,不知道从哪里开始搜索。
Any one have any ideas?
谁有想法?
采纳答案by Ralf
I had exactly the same problem right after switching off some (in my opinion unneccessary) Windows services. It turned out that when I switched ON again the "Application Experience"everything resumed working fine.
在关闭一些(在我看来是不必要的)Windows 服务后,我遇到了完全相同的问题。事实证明,当我再次打开时,"Application Experience"一切都恢复正常。
May be you simply have to turn on this service? To switch ON Application Experience:
可能你只需要打开这个服务?打开应用程序体验:
Click the Windows start buttonn.
In the box labeled "Search programs and files" type
services.mscand click the search button. A new window with title "Services" opens.Right click on "Application Experience" line and select "Properties" from popup menu.
Change Startup type to "Automatic (delayed start)".
Restart computer.
单击 Windows 开始按钮 n。
在标有“搜索程序和文件”的框中键入
services.msc并单击搜索按钮。一个标题为“服务”的新窗口打开。右键单击“应用程序体验”行并从弹出菜单中选择“属性”。
将启动类型更改为“自动(延迟启动)”。
重新启动计算机。
Application Experiences should prevent the problem in the future.
应用程序经验应该可以防止将来出现问题。
回答by Thierry Franzetti
If you think the executable is locked by a process, try Process Explorer from SysInternals. In the File/handle, enter Fibonacci.exe and you should see who holds the file.
如果您认为可执行文件被某个进程锁定,请尝试使用 SysInternals 的 Process Explorer。在文件/句柄中,输入 Fibonacci.exe,您应该会看到谁持有该文件。
If it is not enough, you can use Process Monitor (from SysInternals, again) to follow the activity of all processes on your system on Fibonacci.exe. With a little bit of analysis (call stacks), you'll may find out why the access to the file is denied and what make it disappear.
如果这还不够,您可以使用 Process Monitor(再次来自 SysInternals)在 Fibonacci.exe 上跟踪系统上所有进程的活动。通过一些分析(调用堆栈),您可能会发现为什么拒绝访问文件以及是什么导致它消失。
回答by plodoc
Your program is still running. You have to kill it by closing the command line window. If you press control alt delete, task manager, process`s (kill the ones that match your filename).
您的程序仍在运行。您必须通过关闭命令行窗口来终止它。如果您按 control alt delete、task manager、process`s(杀死与您的文件名匹配的那些)。
回答by Black_Rider
The Best solution is go to console in eclipse IDE and click the red buttonto terminate the program. You will see the your program is running and output can be seen there. :) !!
最好的解决方案是进入 Eclipse IDE 中的控制台,然后单击红色按钮终止程序。您将看到您的程序正在运行,并且可以在那里看到输出。:) !!
回答by Khokhar
Open task manager -> Processes -> Click on .exe (Fibonacci.exe) -> End Process
if it doesn't work
Close eclipse IDE (or whatever IDE you use) and repeat step 1.
打开任务管理器 -> 进程 -> 点击 .exe (Fibonacci.exe) -> 结束进程
如果它不起作用
关闭 Eclipse IDE(或您使用的任何 IDE)并重复步骤 1。
回答by Luis
I had the same behaviour, and fixed it by running Code::Blocks as administrator.
我有相同的行为,并通过以管理员身份运行 Code::Blocks 来修复它。
回答by R. Strickland
I had a similar problem. Using a freeware utility called Unlocker (version 1.9.2), I found that my antivirus software (Panda free) had left a hanging lock on the executable file even though it didn't detect any threat. Unlocker was able to unlock it.
我有一个类似的问题。使用名为 Unlocker(版本 1.9.2)的免费软件实用程序,我发现我的防病毒软件(Panda free)在可执行文件上留下了一个挂锁,即使它没有检测到任何威胁。Unlocker 能够解锁它。
回答by Hey StackExchange
Got the same issue. Read this. Disabled the antivirus software (mcaffee). Et voila
得到了同样的问题。读这个。禁用防病毒软件 (mcaffee)。等等
Confirmed by the antivirus log:
通过杀毒日志确认:
Blocked by Access Protection rule d:\mingw64\x86_64-w64-mingw32\bin\ld.exe d:\workspace\cpp\bar\foo.exe User-defined Rules:ctx3 Action blocked : Create
Blocked by Access Protection rule d:\mingw64\x86_64-w64-mingw32\bin\ld.exe d:\workspace\cpp\bar\foo.exe User-defined Rules:ctx3 Action blocked : Create
回答by Herobrine2Nether
回答by Arun Joshla
Problem Cause :The process of the current program is still running without interuption. (This is the reason why you haven't got this issue after a restart)
问题原因:当前程序的进程仍在运行,没有中断。(这就是你重启后没有出现这个问题的原因)
The fix is simple :Go to cmdand type the command taskkill -im process-name.exe -f
修复很简单:转到cmd并键入命令taskkill -im process-name.exe -f
Eg:
例如:
taskkill -im demo.exe -f
here,
这里,
demo - is my program name
demo - 是我的程序名称


