I'm trying to compile a file in C++ on Cygwin but I keep getting the same error:
Hola! ~/projects/basic-cpp $ g++ main.cpp
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: reopening a.exe: Permission denied
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: final link failed: Permission denied
collect2.exe: error: ld returned 1 exit status
I've seen on other questions on Stack Overflow that this can be caused by the executable being currently run, but I know this is not the case. If I run the command with raised permissions it compiles, so it has something to do with not being able to create the file in the directory because it doesn't have permission.
Also, when I get it to compile by using raised permissions, the file isn't writable by the user. If I compile something using java the *.class file isn't user writable either. If I open and save a new file with emacs the file IS user writable. I feel like there's some serious permission issues with my Cygwin install and any pointers would be helpful.
I had to fully reinstall Cygwin in order to fix this. Something was seriously wrong. I'm still not sure what caused it.
Related
This is my first project with Visual Studio Code. When i go to run my "Hello World" project I get this
cd "c:\Users\imaco\Desktop\Cpppractice" && g++ main.cpp -o main && "c:\Users\imaco\Desktop\Cpppractice"main
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot open output file main.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
my code reads
1 #include <iostream>
2
3
4
5 int main()
6 {
7 std:: cout << "Hello World!";
8 }
-I've made sure it isn't running in the background.
-I've closed and reopened the program and ran the code again with same results.
-I've allowed it as an exception in Bit Defender.
Any help would be greatly appreciated!!
I need 50 reputation to comment, otherwise I would have added a comment. I ran into this issue myself and I solved it using this. However, it worked for me:
"cannot open output file main.exe: Permission denied collect2.exe: error: ld returned 1 exit status"
It says that the permission has been denied. This probably means that you have not given execute access to visual studio in a certain folder or the file has execute restrictions. You could probably be storing this file in a folder that has restricted access. There are a couple of options:
You could probably move it to a new folder that does not have any execute access restrictions.
You may have have to change the permission of that folder/file to read, write and execute using admin privileges.
If this does not work, let me know in the comments section, because I faced the same issue of permission denied.
One of the reasons for this error is that your firewall is blocking "collect2.exe" file. In some cases the firewall is disconnected so you might need to connect with it. Hope it helps !
Try to open terminal (Ctrl + `) and type:
g++ main.cpp then
.\a.exe
(assuming the terminal opens up in your working directory)
This usually happens when VS decides to keep a chunk of code running as a separate entity in the background. A way to fix this is that since you are on Windows, I would right-click the taskbar and click on task manager. This will open up all the tasks that are currently running on the computer. Then, search for "Windows console host." You can change the sorting of the list. Once you find it you can click on it and then at the bottom right it will have an "End Task" available for you to click. Click that and then retry again.
You should be good after that, but let me know if you are still having issues.
when this occurs i usually just remove the exe file and build again
I'm trying to use the following tool: Extract Loudest Section in Windows.
I used the following command line to run main.cc g++ -o main main.cc
But I've got this message: "fatal error: sys/mman.h: No such file or directory"
However, I read this answer, but I still need more details about how to add the needed files correctly to my compiler?
The "Downloads" page in the link provided by the answer shows:
There was an error getting resource 'downloads':
401: Anonymous caller does not have storage.objects.get access to google-code-archive/v2/code.google.com/mman-win32/downloads-page-1.json.
So, I found this as an alternative resource.
I'm using cygwin to compile and windows 10. My question is whenever I try to compile I get an error saying:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld:
cannot open output file a.exe: Permission denied collect2: error: ld returned 1 exit status
It started when I compiled a program that creates a file and then writes to that file, but I don't know why my computer doesn't allow me to create a file in a program. I have no idea how to fix it so I can write to file. Any help is appreciated.
You probably need to run Cygwin as an administrator.
EDIT
I found this:
Root user/sudo equivalent in Cygwin?
Try the accepted answer. It should work.
so I get this error when I run my program:
cannot open output file bin\Debug\PrimeChecker.exe Permission denied
I've already searched this and have found that none of the solutions other people had, applied to me.
Things I have already done:
Changed the directory
Reinstall CodeBlocks
Checked task-manager with anything starting with CodeBlocks (is it maybe listed as something else)
I had no problem running CodeBlocks before this happened and then it just started happening out of the blue.
I'm running on windows 7, if that helps...
Make sure PrimeChecker.exe is not running (for example, in the debugger) when you build. Chances are - this is your problem.
You can go to bin\Debug\PrimeChecker.exe , and try to delete it. you'll probably will not be able to. so find out who is holding a handle for it. I like to use peocessExplorer for this (download free from MS)
It seems the file you are trying to open in your program hasn't read permission. you should change your file permission to be able to write or read to them. this links should be helpful to change your system file permission or attributes.
http://support.microsoft.com/kb/308419
http://www.wikihow.com/Change-File-Permissions-on-Windows-7
I compile a Qt program with C++, and I got this error message:
cannot open output file debug\serbest.exe: Permission denied
collect2: ld returned 1 exit status
What are these command's meaning?
How do I get rid of these errors?
Most likely cause: serbest.exe is still running. Check with TaskManager.
It says the current user is not having enough right to write onto the debug folder. Check whether you can create a new file in the folder as referred to.
run your compiler software as admin. choose your compiler on start menu > right click and run as admin. you wil not probably see any permission denied errors.
Sometimes this error caused because of your antivirus added this file in the limited group.
This helped me!