Sublime Forum

Permission denied error

#1

When I try to run/build my c++ program this is the error I get.
C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/…/lib/gcc/i686-w64-mingw32/8.1.0/…/…/…/…/i686-w64-mingw32/bin/ld.exe: cannot open output file C:\Users\ASUS\Desktop\algo++\lecture-3/Nqueen.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
I have installed the packages and changed the package settings but still is showing this error.

0 Likes

#2

This is either an indication that you literally don’t have permission to modify that file, or that the file already exists and the program is currently running, so Windows is not letting you modify it.

My guess would be the latter, so I would guess that you’re trying to compile a C++ program that’s interactive (i.e. you’re trying to read from stdin to gather input), but that doesn’t work in Sublime Text without more setup.

As a result of this, after running your program once, it’s now sitting in the background waiting for you to give it input, but you can’t. Windows locks executable files while they’re running, so trying to compile and run it again now fails because the linker is trying to link a new version of the file but Windows won’t let it touch the file.

You need to use something like the task manager to kill the program running in the background, and then either not run programs that are interactive, or modify the build system you’re using to work here.

One of the better ways to achieve that is to use the Terminus package to do it. How you do that is documented in the README of the package, but it does require that you be familiar enough with the tools you’re using to know how to compile and run a program so that you can set up the build.

If you’re not sure about how build systems work, this playlist covers the basics of how they work.

This video also has a demonstration on how this works using Terminus, although you would need to substitute your own build system in place of this one. Also this is a little easier in Terminus now than it was when this video was made, so be sure to look at the README of Terminus for details.

0 Likes

#3

I don’t know what may be the technical issues. But I solve the Issue as following

In Sublime, I usually create one file (run.cpp). One day while running the error(access denied) shows. I created a new file (test.cpp) and copied the whole program from run.cpp and pasted in test.cpp there the code run successfully. And later on I deleted the run.cpp file and created a new one.

Hope it’ll work.

0 Likes

#4

If this happens, then one solution is simply delete the .exe file generated after building and running your code and if it says “Cannot delete the file, Try Again”, then open up Task Manager and go to Details and there you’ll find your file_name.exe. Simply right click on that file and choose end process tree and then proceed with deleting or try to run your code again and if fails again then simply delete .exe and do build process again, and you are good to go.

The answer is late but the solution is best :slight_smile:

1 Like