I've used makefile to generate file. gcc -c hello.c -o hello and fixed the permission problem through: chmod a+x ./hello However, when I want to execute "hello" file. ./hello the system told me that "cannot execute binary file" Can someone help me? I am looking forward your reply badly.
3 Answers
The -c argument to gcc produces an object file which you later on must link in order to produce an executable. You can not execute the object file you produced.
Instead, to compile and link at the same time, suitable when you only have 1 .c file, do
gcc hello.c -o hello Or if you want to break it down to separate compilation and linking steps, do
gcc -c hello.c -o hello.o gcc hello.o -o hello
file ./helloplease?