无法打开输出文件 a.out:权限被拒绝,进行简单编译

发布于 2024-10-22 10:30:41 字数 331 浏览 1 评论 0原文

我在 vim 中编写了一些代码,每当我尝试运行代码时,它都会显示:

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

我应该做什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

感悟人生的甜 2024-10-29 10:30:41

移动到允许您写入的目录。

Move to a directory where you are allowed to write.

孤云独去闲 2024-10-29 10:30:41

这是因为如果您只有写权限,但您不是该目录的所有者。

  1. 检查您的用户名:

    <前><代码>whoami

  2. 让您自己成为目录及其内容的所有者:

     sudo chown -R "$USER:" /path/to/the/directory
    
  3. 设置读/写/执行权限

    chmod -R 700 /路径/到/目录
    

请参阅https:// askubuntu.com/questions/466605/cannot-open-output-file-permission-denied

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

同尘 2024-10-29 10:30:41

当您运行 sudo 时,您实际上是以 root 用户身份运行命令。可能您最终搞乱了权限,以便 root 拥有这些文件。因此,当您运行 sudo 时,它就可以工作(root 可以在这些目录中写入)。您需要coolmego 才能拥有这些文件。例如:

sudo chown coolmego /home/coolmego/coolmego/cprograms/
chmod 700 /home/coolmego/coolmego/cprograms/

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/
沙与沫 2024-10-29 10:30:41

删除 /etc/fstab 中的选项用户。 fstab 中包含 user 的任何内容都会自动挂载为 noexec,除非 fstab 中明确给出了 exec。

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

橘虞初梦 2024-10-29 10:30:41

尝试向您要获取输出的目标目录授予读写权限。如果您使用个人系统,您可以执行“sudo chmod 777”

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 "

深海里的那抹蓝 2024-10-29 10:30:41

我遇到了同样的问题,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.

云淡风轻 2024-10-29 10:30:41

尝试 chmod -R 777 ~/coolmego/cprograms

try chmod -R 777 ~/coolmego/cprograms

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文