/mingw32/bin/ld.exe: cannot open output file HelloWorld.exe: Permission denied collect2.exe: error: ld returned 1 exit status

Viewed 7201
#include<iostream>
using namespace std;
int main(){
    cout << "Hello World\n";
    return 0;
} 

This is the Simple program in which I am just printing 'Hello World' but this error occurs everytime.

[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

I have tried everything but unable to produce HelloWorld.exe file and run this code.

3 Answers

If you are using visual studio code you can delete filename.exe (that shows below filename.cpp) then rebuilt it will work.

As shown in image

As shown in image

That's because you have opened this file in the terminal. You must first kill the terminal.

This is because of your anti virus has removed the file or stoped it from executing. Steps to resolve :

  1. Copy your code and delete the file or move to step 2
  2. create a new file and paste your code in it before running the new code make sure you exclude/quarantine your program folder from antivirus scans.(Or turn off antivirus or put it in silent mode)So it no longer deletes or moves your file .
  3. Run the new file it should run fine now :))

Norton file excluding steps

Related