Author Topic: Output file gives "cannot execute binary file: Exec format error"  (Read 7104 times)

Offline turqoisehex

  • Single posting newcomer
  • *
  • Posts: 4
I'm new to Code::Blocks, until now I've written C programs in gedit and compiled with gcc on CLI.
When I compile with:
Code
clang example.c -o example
I get an ~8kb file, and when I run "file example" I get:
Code
example: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=f777e63be4eb01a07e3dea7e1b7adfff47150ded, not stripped

But when I build in C::B I get a 2kb file called example.o. When I file it I get:
Code
example.o: ELF 64-bit LSB  relocatable, x86-64, version 1 (SYSV), not stripped

I've looked inside Settings --> Compiler and everything looks normal to me there. It's set to GCC, clang isn't an option as far as I can see.

When I attempt to run example.o from C::B I get permission denied. Then after changing the permissions I get "cannot execute binary file: Exec format error"

Any suggestions? Thanks.

Offline Дмитро

  • Multiple posting newcomer
  • *
  • Posts: 103
Re: Output file gives "cannot execute binary file: Exec format error"
« Reply #1 on: January 01, 2016, 01:52:24 am »



Hello! I am also a novice, in fact.
I can not exactly understand .. But anyway, IDE makes it easy to compile the program by clicking on and build the desired item in the drop-down list. The finer settings - for which a more complex, not simple tasks.
Happy New year to you!! With a joyful holiday !! :)
« Last Edit: January 01, 2016, 02:03:07 am by Дмитро »

Offline turqoisehex

  • Single posting newcomer
  • *
  • Posts: 4
Re: Output file gives "cannot execute binary file: Exec format error"
« Reply #2 on: January 01, 2016, 03:56:33 am »
Thanks, it doesn't throw any errors when I hit build, but something is definitely wrong with the output file.
Code
gcc -Wextra -Wall -std=c99  -c /home/user/Dropbox/code/example/example.c -o /home/user/Dropbox/code/example/example.o
g++  -o /home/user/Dropbox/code/example/example /home/user/Dropbox/code/example/example.o   
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

When I compile the same source file in Eclipse CDT, it compiles and works normally, though it makes the file about 5 times as big as clang/gcc do... So it seems to me that I've missed something with CB in terms of configuration.
« Last Edit: January 01, 2016, 03:58:48 am by turqoisehex »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7180
    • My Best Post
Re: Output file gives "cannot execute binary file: Exec format error"
« Reply #3 on: January 01, 2016, 04:27:55 am »
You do know that the "example" file and the "example.o" files are two different files, right?

You SHOULD NOT try to run the "example.o" file.

Tim S.

C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline turqoisehex

  • Single posting newcomer
  • *
  • Posts: 4
Re: Output file gives "cannot execute binary file: Exec format error"
« Reply #4 on: January 01, 2016, 08:48:53 pm »
Hi Tim,
Thanks, I feel like an idiot. Build was outputting both "example" and "example.o".  I assumed that example.o was the output of the build and that example was what I'd already output from the CLI. I deleted both and hit build again, and it output both.

Can you tell me what example.o is?

Offline headkase

  • Almost regular
  • **
  • Posts: 159
Re: Output file gives "cannot execute binary file: Exec format error"
« Reply #5 on: January 01, 2016, 09:59:18 pm »
Can you tell me what example.o is?

Dot "o" files are "object files": https://en.wikipedia.org/wiki/Object_file

Which are an intermediate step towards an executable file.

Offline turqoisehex

  • Single posting newcomer
  • *
  • Posts: 4
Re: Output file gives "cannot execute binary file: Exec format error"
« Reply #6 on: January 02, 2016, 04:43:54 am »
Thanks for that. I made the assumption that .o would be shorthand for .out as in a.out, my mistake. Thanks again.

Offline headkase

  • Almost regular
  • **
  • Posts: 159
Re: Output file gives "cannot execute binary file: Exec format error"
« Reply #7 on: January 02, 2016, 10:40:16 am »
Right on, you're welcome.  :)