PDA

View Full Version : cannot execute binary file error



acmariner99
April 13th, 2009, 06:33 AM
I am compiling a C program. Below is what I use to compile and execute on the command line.

gcc -o programtorun programtorun.h

./programtorun

"cannot execute binary file"


please help

lisati
April 13th, 2009, 06:37 AM
I'm curious: why are you compiling a ".h" file?

acmariner99
April 13th, 2009, 06:40 AM
that was how I learned to compile. I set up main, and call a User interface function (within the .h file). I presume I can set up everything within the .c file without the UI function and compile and run that?

mltucker
April 13th, 2009, 06:42 AM
Just put



#include "myHeader.h"


(where myHeader.h has the UI function) at the top of the .c file, and then run your gcc command on the .c file. You compile the file that has the main method. This makes sense since lots of programs could use that header file.

-Mark

lisati
April 13th, 2009, 06:43 AM
that was how I learned to compile. I set up main, and call a User interface function (within the .h file). I presume I can set up everything within the .c file without the UI function and compile and run that?

As far as I know, it is more usual to have a ".c" file which you compile, and use C's "#include" to pull in extra stuff from ".h" files as required.

acmariner99
April 13th, 2009, 06:46 AM
problem solved thanks!

acmariner99
April 13th, 2009, 06:47 AM
I compiled the .c file instead and have an include to the UI function. Thank you!

hessiess
April 13th, 2009, 09:53 AM
Dont put function implementations in header files, they are for function declarations, and preprosessor macros.