«No such file or directory» error when trying to execute a binary [duplicate]
nasm -f elf64 test64.asm successfully creates test64.o and ld -s -o hello test64.o -lc creates an executable file, but when I try to run it, I get a «No such file or directory» error.
Regarding the edit — I’m adding Linux tag back in. This code, is compiled with NASM; is about running executables in a Linux like environment (confirmed with the fact we are tagged as Ubuntu); and the linker target is ELF64. I would suggest that given that information, that Linux is still an applicable tag because it is a question about software development in a Linux environment, and to fix the issue will require a Linux specific solution.
2 Answers 2
1) You’re using the wrong calling convention for printf . The arguments were passed in registers, not on the stack: https://en.wikipedia.org/wiki/X86_calling_conventions#System_V_AMD64_ABI. Also, printf needs a value in EAX (0 in your case).
is wrong. But if you use the 64-bit-Linux-syscall
mov edi, 0 ; return 0 (success) mov eax, 60 ; sys_exit syscall
you will not see the output of printf , because it is buffered and the buffer won’t be flushed. You can call fflush(0) or exit .
3) To use C functions in Linux you have to link with a special loader ( /lib64/ld-linux-x86-64.so.2 ). I just don’t know if it is installed by default.
4) push val1 pushes the address of val1, not its value. Use brackets to get the values. I guess you wanted just load a 32-bit DWORD into a 64-bit register. You can directly load the DWORD into a 32-bit register (the upper part of the 64-bit-register will be cleared) or use movsx for a signed operation.
section .data fmt db `%d\n`,0 ; backticks for '\n' val1 dd 23 val2 dd 9 val3 dd 7 section .text global _start extern printf, exit _start: movsx rax, dword [val1] ; signed dword to signed qword movsx rbx, dword [val2] imul rax, rbx mov ebx, [val3] ; unsigned dword into RBX add rax, rbx mov [val1], rax mov rdi, fmt ; string pointer mov rsi, [val1] ; immediate value xor eax, eax ; no vector registers used call printf xor edi, edi call exit
nasm -f elf64 test64.asm
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o test64 test64.o -lc
./test64
No such file or directory? But the file exists!
I’ve downloaded a game (Shank) but the bin file doesn’t run. The error that is shown when I try to launch the executable is:
bash: ./shank-linux-120720110-1-bin: No such file or directory
Thank you for your reply. I’ve done the command you said Agent86 but I have the same result. I’ve downloaded also the .deb file but there is a problem too. I don’t know what problem has this game.
Please confirm whether you’re running a 64-bit installation (that’s the most common case for this problem).
9 Answers 9
You’re probably trying to run a 32-bit binary on a 64-bit system that doesn’t have 32-bit support installed.
There are three cases where you can get the message “No such file or directory”:
- The file doesn’t exist. I presume you’ve checked that the file does exist (perhaps because the shell completes it).
- There is a file by that name, but it’s a dangling symbolic link.
- The file exists, and you can even read it (for example, the command file shank-linux-120720110-1-bin displays something like “ELF 32-bit LSB executable …”), and yet when you try to execute it you’re told that the file doesn’t exist.
The error message in this last case is admittedly confusing. What it’s telling you is that a key component of the runtime environment necessary to run the program is missing. Unfortunately, the channel through which the error is reported only has room for the error code and not for this extra information that it’s really the runtime environment that’s to blame. If you want the technical version of this explanation, read Getting “Not found” message when running a 32-bit binary on a 64-bit system.
The file command will tell you just what this binary is. With a few exceptions, you can only run a binary for the processor architecture that your release of Ubuntu is for. The main exception is that you can run 32-bit (x86, a.k.a. IA32) binaries on 64-bit (amd64, a.k.a. x86_64) systems.
In Ubuntu up to 11.04, to run a 32-bit binary on a 64-bit installation, you need to install the ia32-libs package . You may need to install additional libraries (you’ll get an explicit error message if you do).
Since 11.10 (oneiric) introduced multiarch support, you can still install ia32-libs , but you can choose a finer-grained approach, it’s enough to get libc6-i386 (plus any other necessary library).
Debugging the error «gcc: error: x86_64-linux-gnu-gcc: No such file or directory»
x86_64-linux-gnu-gcc definitely exists in /usr/bin (It’s a symlink) and the target definitely exists as well. It looks to me like the Makefile wasn’t generated correctly, perhaps there is a flag that should be passed before specifying x86_64-linux-gnu-gcc? I am unsure as well what specifying x86_64-linux-gnu-gcc is supposed to accomplish. Finally, this makefile was generated by configure, so once we narrow down the cause of the error, I’ll have to figure out what files to modify in order to fix this. (I’m a CMake kind of guy myself, but of course I didn’t choose the build system for this project.) My OS is Debian. I’ve tried building this branch as well: https://github.com/kanzure/nanoengineer/branches/kirka-updates If you can try getting this to build on your system, I would greatly appreciate it! Thanks!
How did you invoke the configure script? It looks like you added garbage to CXXFLAGS or something. Where does x86_64-linux-gnu-gcc appear inside the Makefile ?
Yes, python-dev is installed. I invoked configure with «./configure». I greped the entire 449MB (!) source tree for x86_64-linux-gnu-gcc but no results. I also tried building on a different machine, and I ended up with the exact same error. I appreciate the help. Thanks!!
cat pants, please, run the gcc command with -v option added and post its output. Actually the error in the posted command is gcc . options. x86_64-linux-gnu-gcc ..options.. and gcc trys to use x86_64-linux-gnu-gcc as input file, which is wrong. So, you should debug the Makefile.
@AndyG That’s where the error is coming from — the command being run is gcc . x86_64-linux-gnu-gcc . — gcc doesn’t see the x86_64-linux-gnu-gcc argument as an option/flag/etc, so assumes it is a file that it is supposed to compile. Since it has no path attached, it assumes that the file should be in the current directory, doesn’t find it, and produces the error message. Why that command line is what it is, though is an issue with configure or how it was run, or with the Makefile — the command as listed does not make sense.