41

I have a file called commanKT and want to run it in a Linux terminal. Can someone help by giving the command to run this file? I tried ./commonRT but I'm getting the error:

"bash: ./commonrt: cannot execute binary file"

[blackberry@BuildMc MainApp]$ ls -al commonKT
-rwxrwxr-x. 1 sijith sijith 10314053 Feb 27 16:49 commonKT
6
  • 1
    are you sure it's executable? try to use command file
    – meteorgan
    Commented Feb 28, 2012 at 6:10
  • 4
    Assuming the problem isn't just a mixup over names (commonrt vs commonKT), what does the command file commonKT /bin/sh say? If it gives two different architectures (perhaps one for ARM and one for Intel), then that's why you can't run the ARM one on an Intel machine. Commented Feb 28, 2012 at 6:54
  • 1
    In addition of using file, I also suggest using ldd; perhaps the dynamic linker or some core shared library is different or missing.... Commented Feb 28, 2012 at 7:03
  • Sorry for wrong file name...The actual file name is commanrt and what is this file name means
    – Sijith
    Commented Feb 28, 2012 at 10:11
  • 1
    Why does this question have so many upvotes? It contains so many variants of the questioned filename (commonrt, commonKT, commanKT, commonRT), that it's not even clear what was asked. Also interesting: Does the last comment of Sijith mean that it is answered? And why did user1978011 receive bountys? Commented Jan 17, 2018 at 9:39

14 Answers 14

65

To execute a binary, use: ./binary_name.

If you get an error:

bash: ./binary_name: cannot execute binary file

it'll be because it was compiled using a tool chain that was for a different target to that which you're attempting to run the binary on.

For example, if you compile 'binary_name.c' with arm-none-linux-gnueabi-gcc and try run the generated binary on an x86 machine, you will get the aforementioned error.

1
  • How to run the binary which is generated using the tool chain ? Commented Nov 25, 2020 at 13:37
33

To execute a binary or .run file in Linux from the shell, use the dot forward slash friend

 ./binary_file_name

and if it fails say because of permissions, you could try this before executing it

 chmod +x binary_file_name
 # then execute it
 ./binary_file_name
1
7

The volume it's on is mounted noexec.

5

:-) If not typo, why are you using ./commonRT instead of ./commonKT ??

1
  • even ./commonrt in all lowercase. :) Commented Feb 28, 2012 at 14:42
4
+50

It is possible that you compiled your binary with incompatible architecture settings on your build host vs. your execution host. Can you please have a look at the enabled target settings via

g++ {all-your-build-flags-here} -Q -v --help=target

on your build host? In particular, the COLLECT_GCC_OPTIONS variable may give you valuable debug info. Then have a look at the CPU capabilities on your execution host via

cat /proc/cpuinfo | grep -m1 flags

Look out for mismatches such as -msse4.2 [enabled] on your build host but a missing sse4_2 flag in the CPU capabilities.

If that doesn't help, please provide the output of ldd commonKT on both build and execution host.

1
  • 1
    @craq I see that you gave me your bounty, thanks! Can you please give some info what the error was about? Commented Apr 30, 2015 at 15:27
2

This is an answer to @craq :

I just compiled the file from C source and set it to be executable with chmod. There were no warning or error messages from gcc.

I'm a bit surprised that you had to 'set it to executable' -- my gcc always sets the executable flag itself. This suggests to me that gcc didn't expect this to be the final executable file, or that it didn't expect it to be executable on this system.

Now I've tried to just create the object file, like so:

$ gcc -c -o hello hello.c
$ chmod +x hello

(hello.c is a typical "Hello World" program.) But my error message is a bit different:

$ ./hello
bash: ./hello: cannot execute binary file: Exec format error`

On the other hand, this way, the output of the file command is identical to yours:

$ file hello
hello: ELF 64-bit LSB  relocatable, x86-64, version 1 (SYSV), not stripped

Whereas if I compile correctly, its output is much longer.

$ gcc -o hello hello.c
$ file hello
hello: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=131bb123a67dd3089d23d5aaaa65a79c4c6a0ef7, not stripped

What I am saying is: I suspect it has something to do with the way you compile and link your code. Maybe you can shed some light on how you do that?

2

The only way that works for me (extracted from here):

chmod a+x name_of_file.bin

Then run it by writing

./name_of_file.bin

If you get a permission error you might have to launch your application with root privileges:

 sudo ./name_of_file.bin
1

your compilation option -c makes your compiling just compilation and assembly, but no link.

0

Or, the file is of a filetype and/or architecture that you just cannot run with your hardware and/or there is also no fallback binfmt_misc entry to handle the particular format in some other way. Use file(1) to determine.

0

If it is not a typo, as pointed out earlier, it could be wrong compiler options like compiling 64 bit under 32 bit. It must not be a toolchain.

0

To run binary file in Linux, firstly check the permission and make sure you have "x" granted to your user/ group or others.

ll <binary_file_name>

Depends on the user you are logging in, if you "x" which stands for execution, you are good to go.

If no permission is set for execution, then simply execute below command.

chmod a+x <binary_name> --> this will execution permission to the binary no matter user/ group or others. 

then execute the following command for binary execution:

./<binary_file_name>
0

I fix the problem removing -c flag

gcc -o example.out example.cpp
1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Oct 26, 2023 at 16:52
-1

full path for binary file. For example: /home/vitaliy2034/binary_file_name. Or use directive "./+binary_file_name". './' in unix system it return full path to directory, in which you open terminal(shell). I hope it helps. Sorry, for my english language)

-2

1st login with su

su <user-name>

enter password

Password: xxxxxx

Then executer command/file, it should run.

Not the answer you're looking for? Browse other questions tagged or ask your own question.