在 Windows 7 上使用 GCC 编译:\mingw32\bin\ld.exe:无法打开输出文件 a.exe

发布于 2024-09-13 21:58:26 字数 571 浏览 8 评论 0原文

这是我尝试使用 gcc 编译一个简单的 hello world 程序时得到的结果。

c:\>gcc hello.c
hello.c:9:2: warning: no newline at end of file
C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot open output file a.exe
: Permission denied
collect2: ld returned 1 exit status

和windows 7管理权限有关系吗?

如果正在创建输出文件但无法打开,它位于哪里?

抱歉,如果这个问题太菜鸟了。到目前为止,我一直使用 Dev-C++ 来编译我的源代码。我尝试用谷歌搜索该错误,但我所能找到的只是该文件已经打开,但任务管理器中没有提及此类 exe。

编辑:该文件也位于 C:\hello.c

如果我将其放在其他驱动器中,我可以这样做吗?

当我将文件放在 D:\ 并尝试使用 cd d:\ 将其更改为任何其他驱动器时,不会更改驱动器。

This is what I get when trying to compile a simple hello world program with gcc.

c:\>gcc hello.c
hello.c:9:2: warning: no newline at end of file
C:\MinGW\bin\..\lib\gcc\mingw32\3.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?

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.

Edit: Also the file is located at 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

糖果控 2024-09-20 21:58:26

是的,这是一个权限问题,您不能在管理模式下运行命令行窗口。

不适用于 C:\

将文件复制到我的文档下的文件夹、C: 的子文件夹或其他驱动器。

或者,如果您确实想在 C: 的根目录中工作,请在管理员模式下运行控制台。

要在 C: 中切换到 D:,只需键入 D:(仅当已位于正确的驱动器上时才使用 CD)

Yes it is a permissions issue, you must not be running the command line window in Admin mode.

Don't work in C:\

Copy the file to a folder under my documents, or a subfolder of C:, or another drive.

Or, run the console in Administrator mode if you really want to work in the root of C:

To switch to D: while in C:, just type D: (you use CD only when already on the correct drive)

眉黛浅 2024-09-20 21:58:26

最常见的情况是您的程序可能仍在后台运行,可能挂在无限循环上。您可以尝试在进程列表中搜索该进程(按Alt+Ctrl+Del)并将其杀死。

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.

作妖 2024-09-20 21:58:26

我发现问题在于在 google 驱动器下托管 src;.. 天哪,超级明星查克·诺里斯·范·达姆 (chuck Norris van Damm) .. 3 小时试图弄清楚这个问题(与代码 + mingw64 相比)。

解决方案:
刚刚将带有我的 cpp 源文件的文件夹移到了 google 驱动器管理的文件夹树(位于 f:\gd 上)之外,因此将我的源移到了 f:\dev 中。

I found problem was hosting src under google drive;.. jesus super star chuck norris van damm .. 3h trying to figure out this one (vs code + mingw64).

Solution:
Just moved the folder with my cpp source file outside google drive managed folder tree (was on f:\gd) so moved my source into f:\dev.

离笑几人歌 2024-09-20 21:58:26

CodeBlocks-IDE 中的构建日志中的 g++.exe-command 显示了该命令
带有附加路径:C:\MinGW\lib,这是错误的。

  1. 如果您将命令复制到cmd窗口(在您的项目目录中)
    如果没有 C:\MinGW\lib 编译器也可以工作。当您按照 CodeBlocks-Buil-log 中所示复制命令时,它会失败,并在 cmd 窗口中显示相同的消息。

  2. 看看设置>编译器>搜索目录>链接器。你必须删除
    C:\MinGW\lib 在那里,但错误是,如果你这样做了一次,它就不会被删除。
    您必须重复此操作,然后它才会起作用。

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.

  1. If you copy the command to a cmd-window (in the directory of your Project)
    without the C:\MinGW\lib the compiler works. When you copy the command as shown in CodeBlocks-Buil-log it fails, with the same message in the cmd-window.

  2. Have a look at the Settings > Compiler > Search Directories > Linker. You've got to delete the
    C:\MinGW\lib there, but the bug is, that it is not deleted if you do it once.
    You've got to repeat it and then it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文