简体   繁体   English

Ubuntu:: ./program: 权限被拒绝

[英]Ubuntu:: ./program: Permission Denied

Firstly, my problem is similar to this: Ubuntu says "bash: ./program Permission denied"首先,我的问题与此类似: Ubuntu 说“bash: ./program Permission denied”

However, I feel the need to further clarify.但是,我觉得有必要进一步澄清。

When I compile my program using:当我使用以下命令编译我的程序时:

gcc -c file.c -o file

and run并运行

./file 

I get this error:我收到此错误:

bash:./file: Permission denied

When I use当我使用

chmod u+x file 

and then run然后运行

./file

I get this error:我收到此错误:

bash: ./file: cannot execute binary file: Exec format error

However, when I compile using但是,当我编译时使用

gcc file.c -o file <br/>

My program runs perfectly well using我的程序运行得很好

./file

Can someone point out what is the problem with using the -c argument with gcc ?有人可以指出将-c参数与gcc一起使用有什么问题吗?

Type gcc --help to see some help.键入gcc --help以查看帮助。

-c                      Only run preprocess, compile, and assemble steps

This means that, when run with this option, GCC doesn't link the executable with any (even system) libraries.这意味着,当使用此选项运行,GCC不可执行文件与任何(甚至系统)库链接

In short, to run a program, the OS needs a starting point, which is located in some system library.简而言之,要运行一个程序,操作系统需要一个起点,它位于某个系统库中。 Since in your case GCC isn't linking the executable with anything , the OS doesn't know how to run the file , where to start.由于在您的情况下 GCC 没有将可执行文件与任何内容链接,因此操作系统不知道如何运行该文件,从哪里开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM