Reputation: 647
I wrote some code in vim and whenever I try to run the code it shows this:
coolmego@coolmego-PC:~/coolmego/cprograms$ gcc dfs8puzz.c
/usr/bin/ld: cannot open output file a.out: Permission denied
collect2: ld returned 1 exit status
coolmego@coolmego-PC:~/coolmego/cprograms$ ./a.out
bash: ./a.out: No such file or directory
What should I do?
Upvotes: 7
Views: 63103
Reputation: 1
I was having the same problem, after 1 hour i found out it was my Antivirus, i shut that down and everything worked fine.
Upvotes: -1
Reputation: 41
This is because if you only have write permissions, but you are not the owner the directory.
Check your user name:
whoami
Make yourself the owner of the directory and its contents:
sudo chown -R "$USER:" /path/to/the/directory
Set read/write/execute permission
chmod -R 700 /path/to/the/directory
refer https://askubuntu.com/questions/466605/cannot-open-output-file-permission-denied
Upvotes: 4
Reputation: 697
Try giving read write permission to the directory in which you are targeting to get the output. In case you are using a personal system you can do "sudo chmod 777 "
Upvotes: 0
Reputation: 1900
Remove option user in /etc/fstab. Anything with user in the fstab is automatically mounted noexec unless exec is explicitly given in the fstab.
Upvotes: 0
Reputation: 26281
When you run sudo, you are actually running the commands as root user. Possibly you ended up messing up the permissions so that root owns the files. Thus when you run sudo, it just works (root can write in those directories). You need coolmego to own those files. For example:
sudo chown coolmego /home/coolmego/coolmego/cprograms/
chmod 700 /home/coolmego/coolmego/cprograms/
Upvotes: 0