Results 1 to 8 of 8
Hi,
I wrote a simple "Hello World!" program in C and compiled it on a unix machine. Now I am trying to run the executable on a linux virtual machine, ...
- 03-30-2008 #1Just Joined!
- Join Date
- Mar 2008
- Posts
- 3
[SOLVED] -bash: ./a.out: cannot execute binary file
Hi,
I wrote a simple "Hello World!" program in C and compiled it on a unix machine. Now I am trying to run the executable on a linux virtual machine, but when I try the command
./a.out
to execute the compiled program, I get the error
-bash: ./a.out: cannot execute binary file
Any thoughts?
Thanks!
- 03-30-2008 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
welcome to the forum: need more programmers around here
is the file executable? try either
1 chmod a+x a.out, or
2 . ./a.out
note the first dotthe sun is new every day (heraclitus)
- 03-31-2008 #3Nope. That would be a permissions issue, and bash (if that's the shell you're running, which you most likely are) would say something likeis the file executable? try either
1 chmod a+x a.out, or
Code:-bash: ./1: Permission denied
Nope. Not that either. The first dot in that command:2 . ./a.out
note the first dot
is fine for getting around the permissions problem, but it won't work here because it tells bash (or whatever shell you're running) to interpret the content of this file as a set of bash statements.Code:. ./a.out
Your problem is most likely that you're compiling it on one platform (some UNIX platform) and it's being run on another (Linux). You might even be using different machine architectures (Intel x86 versus Sun or IBM or HP or DEC, for example). In that case, if you wish to compile on one kind of machine and run the compiled output on another, you need to use a cross compiler.
Hope this helps.--
Bill
Old age and treachery will overcome youth and skill.
- 03-31-2008 #4Linux User
- Join Date
- Jan 2005
- Location
- Saint Paul, MN
- Posts
- 262
Did you compile it or compiled and linked?
This compiles the program...
cc -c hello_world.c
This compiles and links the program:
cc hello_world.c
This compiles and links the progam putting the executable into "hello_world".
cc -o hello_world hello_world.c
By default on a Unix/Linux system the current directory is not in the execution path and therefore you need to tell it where it is:
./a.out
or
./hello_world
The current directory is not in the path for security reasons as local executables could be used to replace system executables.
- 03-31-2008 #5It's almost certain that he compiled and linked it, because a.out is the default filename for linked programs.Did you compile it or compiled and linked?
According to the original post, that's exactly what he did, so that's not the problem.By default on a Unix/Linux system the current directory is not in the execution path and therefore you need to tell it where it is:
./a.out
Once again, he probably needs to look into cross compilation.--
Bill
Old age and treachery will overcome youth and skill.
- 03-31-2008 #6
thanks for links on Cross compiler.
OT: wje_lf,your second link for Cross compiler is broken.
Code:... he probably needs to look into cross compilation.
- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 03-31-2008 #7Not off topic at all. Broken links should be ashamed of themselves. :)OT: wje_lf,your second link for Cross compiler is broken.
My intent was for that second link, in post #5 in this thread, to point not to the wikipedia article, but simply to post #3 in general. I tested it just now, and it still seems to do that. :)--
Bill
Old age and treachery will overcome youth and skill.
- 03-31-2008 #8Just Joined!
- Join Date
- Mar 2008
- Posts
- 3
Thanks for all the help to everyone who posted in response to my problem.
I found out from the TA of my course that my specific problem is that I am compiling on a 64-bit machine and trying to execute the program on a 32-bit machine.
To fix this problem, all I have to do is add the flag "-m32" when I compile the source code.
Thanks again!



