Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot execute binary files on MAC terminal

Tags:

c

shell

macos

gcc

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.

like image 579
Immanuel Chen Avatar asked Jun 09 '26 23:06

Immanuel Chen


2 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
like image 188
nos Avatar answered Jun 11 '26 16:06

nos


Check whether the GCC compiler is installed in your system correctly or not.

gcc -v

Compile your file:

gcc filename.cpp -o any-name

Running your program:

./any-name
like image 40
Xchg0x5f375d Avatar answered Jun 11 '26 16:06

Xchg0x5f375d



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!