C语言 在 Windows 7 上使用 GCC 编译:\mingw32\bin\ld.exe:无法打开输出文件 a.exe
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3451816/
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
Compiling with GCC on windows 7: \mingw32\bin\ld.exe: cannot open output file a.exe
提问by stirredo
This is what I get when trying to compile a simple hello world program with gcc.
这就是我在尝试用 gcc 编译一个简单的 hello world 程序时得到的结果。
c:\>gcc hello.c
hello.c:9:2: warning: no newline at end of file
C:\MinGW\bin\..\lib\gcc\mingw32.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot open output file a.exe
: Permission denied
collect2: ld returned 1 exit status
Does it have something to do with windows 7 administrative privileges?
它与Windows 7管理权限有关吗?
If the output file is being created but cannot be opened, where is it located?
如果正在创建输出文件但无法打开,它位于何处?
Sorry if this is too much of a noobie question. I have been using Dev-C++ for compiling my source code till now. I tried googling around the error but all i could find was the file is already open, but there is no mention of such exe in task manager.
对不起,如果这是一个太多的菜鸟问题。到目前为止,我一直在使用 Dev-C++ 来编译我的源代码。我试着在谷歌上搜索错误,但我能找到的只是文件已经打开,但在任务管理器中没有提到这样的 exe。
Edit: Also the file is located at C:\hello.c
编辑:该文件也位于 C:\hello.c
Will i be able to do it if i place it in other drive?
如果我把它放在其他驱动器上,我能做到吗?
When i place the file at D:\ and try change it to any other drive using cd d:\ doesn't change the drive.
当我将文件放在 D:\ 并尝试使用 cd d:\ 将其更改为任何其他驱动器时,不会更改驱动器。
回答by Fosco
Yes it is a permissions issue, you must not be running the command line window in Admin mode.
是的,这是一个权限问题,您不能在管理员模式下运行命令行窗口。
Don't work in C:\
不要在 C:\
Copy the file to a folder under my documents, or a subfolder of C:, or another drive.
将文件复制到我的文档下的文件夹,或 C: 的子文件夹,或其他驱动器。
Or, run the console in Administrator mode if you really want to work in the root of C:
或者,如果您真的想在 C 的根目录下工作,请以管理员模式运行控制台:
To switch to D: while in C:, just type D: (you use CD only when already on the correct drive)
要切换到 D:,而在 C: 中,只需键入 D:(仅当已经在正确的驱动器上时才使用 CD)
回答by alecov
The most common case is that your program may still be running in the background, possibly hanged on an endless loop. You can try searching for the process in the process list (press Alt+Ctrl+Del) and killing it.
最常见的情况是您的程序可能仍在后台运行,可能会陷入无限循环。您可以尝试在进程列表中搜索该进程(按Alt+ Ctrl+ Del)并杀死它。
回答by Hubert
The g++.exe-command in the build-log in the CodeBlocks-IDE shows the command
with an additional path: C:\MinGW\lib, which is wrong.
CodeBlocks-IDE 的构建日志中的 g++.exe-command 显示了带有附加路径的命令:C:\MinGW\lib,这是错误的。
If you copy the command to a cmd-window (in the directory of your Project) without the
C:\MinGW\libthe compiler works. When you copy the command as shown inCodeBlocks-Buil-logit fails, with the same message in the cmd-window.Have a look at the
Settings > Compiler > Search Directories > Linker. You've got to delete theC:\MinGW\libthere, but the bug is, that it is not deleted if you do it once. You've got to repeat it and then it works.
如果您将命令复制到 cmd 窗口(在您的项目目录中),
C:\MinGW\lib则编译器无法正常工作。当您复制命令CodeBlocks-Buil-log失败时,在 cmd 窗口中显示相同的消息。看看
Settings > Compiler > Search Directories > Linker。你必须删除C:\MinGW\lib那里的,但错误是,如果你这样做一次,它不会被删除。你必须重复它,然后它才能起作用。

