sd1517
sd1517

Reputation: 647

cannot open output file a.out: Permission denied, on a simple compilation

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

Answers (7)

Sahil  Rai
Sahil Rai

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

Vijay Anand
Vijay Anand

Reputation: 41

This is because if you only have write permissions, but you are not the owner the directory.

  1. Check your user name:

    whoami
    
  2. Make yourself the owner of the directory and its contents:

     sudo chown -R "$USER:" /path/to/the/directory
    
  3. 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

Srijan Chaudhary
Srijan Chaudhary

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

Gabriel
Gabriel

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

Foo Bah
Foo Bah

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

delete_this_account
delete_this_account

Reputation: 2446

try chmod -R 777 ~/coolmego/cprograms

Upvotes: -5

unwind
unwind

Reputation: 400159

Move to a directory where you are allowed to write.

Upvotes: 8

Related Questions