Sirius Wang
Sirius Wang

Reputation: 349

mac osx yosemite gcc cannot execute binary file , command not found

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?

Upvotes: 2

Views: 4457

Answers (1)

Sasha Pachev
Sasha Pachev

Reputation: 5336

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

Upvotes: 8

Related Questions