13

I was given a "binary" file on linux and a seperate file for windows for a particular task. The programs is an exe on windows. A linux version of the file has the same function on linux as it had windows, too.

However, I've failed to be able to execute this. I tried (on the terminal) to execute it by just the file name, ./[filename], and even tried chmod +x [filename] and then tried the second way.

For everything... I get the result: "Command not found". (The file is definitely there, by the way).

What am I supposed to do? The file command on it yields:

ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=e805f746e65c09cc8b0c037d8a8c27ee0a6a051c
8
  • 1
    using the file command yields this: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=e805f746e65c09cc8b0c037d8a8c27ee0a6a051c, stripped
    – hexcode
    Nov 7, 2016 at 5:19
  • 2
    Do you have a /lib/ld-linux.so.2 on your system? This will happen if you try to run a 32 bit executable on a 64bit system or vice versa without the required libraries installed, out if you run an executable compiled for a different distribution Nov 7, 2016 at 5:22
  • 1
    I've got this: /lib/ld-linux-x86-64.so.2
    – hexcode
    Nov 7, 2016 at 5:24
  • 3
    As file tells you, you very specifically need /lib/ld-linux.so.2. It appears that you are trying to run an i386 executable on an amd64 system. On Ubuntu/Debian systems, you could apt-get install libc6-i386 to install the support libraries to run i386 executables.
    – Dan Lenski
    Nov 7, 2016 at 5:33
  • 2
    Also, use ldd rather than file to show more informative details about the libraries required by the executable (possibly more than just libc6).
    – Dan Lenski
    Nov 7, 2016 at 5:34

2 Answers 2

14

My guess is that this is 32 bit compile on a 64 bit system. I cross compiled a small c file into a binary using the -m32 option on gcc. This also needed a few extra packages. The resulting a.out looks like this.

% file a.out
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=be02470c8337b96e7deaaff323bc53865991c3ab, not stripped

Compare this to a native system binary

% file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=a0823e17cafbe5b2296346216445566840fdfd88, stripped

Running the a.out shows me this.

% ./a.out
zsh: no such file or directory: ./a.out

The specific "Command not found" message is something, I think, bash prints. I use zsh myself.

To get this to work, you can install the multilib packages. I didn't narrow it down to the exact package but installing gcc-multilib on Debian pulls in everything you need. After installing that, here's what I get.

% ./a.out
3.140523

(the program is supposed to estimate the value of PI).

Note: I actually needed to install gcc-multilib just to compile the file. I then uninstalled the packages to mimic a 64 bit system that doesn't have the 32 bit runtime libraries that the thing needs.

1
  • 1
    apt install gcc-multilib
    – Arash
    Jan 8, 2021 at 1:53
0

does the a.out have executable permission ?

check with ls -la cmd and if does no then add the permission using chmod a+x a.out an d then try executing

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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