2

This article : https://superuser.com/questions/724301/how-to-solve-bash-cannot-execute-binary-file can not help me to solve my problem.

The step is below:

gcc -c hello.c -o hello.o 

when I enter command :

./hello.o 

the message is :

./hello.o: command not found

I try this:

chmod 755 ./hello.o 

execute again, the message is :

-bash: ./hello.o: cannot execute binary file

I have checked the file version, it is Mach-O format for binaries.

I enter this command:

file ./hello.o 

it shows:

./hello.o: Mach-0 64-bit object x86_64

How can I solve this problem?

1 Answer 1

8

Remove -c from the compilation command. With -c you are producing an object file, not an executable. And probably you do not want to call your executable hello.o as the convention is for .o files to be object files. So gcc -o hello hello.c; ./hello

Sign up to request clarification or add additional context in comments.

2 Comments

I forgot this is an object file! However, Do I need to link this object file If I want to make this object file executable? gcc hello -o hello_executable . I do this command, and it do work.Thanks for your help!
gcc does the linking for you after it compiles automatically.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.