Find the answer to your Linux question:
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, ...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    3

    Talking [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!

  2. #2
    tpl
    tpl is offline
    Linux 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 dot
    the sun is new every day (heraclitus)

  3. #3
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    is the file executable? try either
    1 chmod a+x a.out, or
    Nope. That would be a permissions issue, and bash (if that's the shell you're running, which you most likely are) would say something like
    Code:
    -bash: ./1: Permission denied
    2 . ./a.out
    note the first dot
    Nope. Not that either. The first dot in that command:
    Code:
    . ./a.out
    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.

    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.

  4. #4
    Linux User
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    262
    Quote Originally Posted by djk37 View Post
    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!
    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.

  5. #5
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Did you compile it or compiled and linked?
    It's almost certain that he compiled and linked it, because a.out is the default filename for linked programs.
    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
    According to the original post, that's exactly what he did, so that's not the problem.

    Once again, he probably needs to look into cross compilation.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  6. #6
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Post

    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
    -------------------

  7. #7
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    OT: wje_lf,your second link for Cross compiler is broken.
    Not off topic at all. Broken links should be ashamed of themselves. :)

    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.

  8. #8
    Just 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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...