【发布时间】:2021-02-07 23:37:16
【问题描述】:
#include<iostream>
using namespace std;
int main(){
cout << "Hello World\n";
return 0;
}
这是一个简单的程序,我只是在其中打印“Hello World”,但每次都会出现这个错误。
[Running] cd "e:\C++\Data Types\" && g++ HelloWorld.cpp -o HelloWorld && "e:\C++\Data Types\"HelloWorld
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot open output file HelloWorld.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
我已经尝试了所有方法,但无法生成HelloWorld.exe 文件并运行此代码。
【问题讨论】:
-
这意味着您的防病毒软件已打开文件,或者您仍在运行以前的可执行文件,或者您的用户没有权限写入文件存在权限问题。我的投票是第一个,特别是如果您使用的防病毒软件与操作系统附带的防病毒软件不同。
-
@drescherjm 防病毒软件正在阻止
HelloWorld.exe运行,因此为了运行它,我禁用了防病毒软件保护,但问题仍然存在。 -
浏览到文件夹
e:\C++\Data Types\HelloWorld并查看文件是否存在 -
我的第二条建议是在 c++ 编程中永远不要使用带有空格的路径。
-
某些 AV 具有沙盒模式,如果激活该模式会导致 c++ 软件无法运行。我已经用 aVast 看到了这一点。我的代码通常有一个特殊的根文件夹,如
c:\programming或像x:这样的驱动器,并告诉我的 AV 忽略整个树。
标签: c++ c++11 visual-studio-code