开发者

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 df开发者_Python百科s8puzz.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?


Move to a directory where you are allowed to write.


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


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/


Remove option user in /etc/fstab. Anything with user in the fstab is automatically mounted noexec unless exec is explicitly given in the fstab.


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 "


I was having the same problem, after 1 hour i found out it was my Antivirus, i shut that down and everything worked fine.


try chmod -R 777 ~/coolmego/cprograms

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜