-3

Firstly, my problem is similar to this: Ubuntu says "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?

Community
  • 1
  • 1
frags51
  • 33
  • 6
  • 1
    So, did you read the gcc documentation? What `-c` does? What did you not understand? Did you search first for it? If not: what other research effort did you do before asking? – too honest for this site Sep 24 '16 at 19:47
  • And BTW, GCC documentation is here: https://gcc.gnu.org/onlinedocs/gcc/ – alk Sep 25 '16 at 09:16

1 Answers1

3

Type gcc --help to see some 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.

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.

ForceBru
  • 43,482
  • 10
  • 63
  • 98