NASM on Virtual Machine Ubuntu: Cannot execute binary file exec format error

≯℡__Kan透↙ 提交于 2019-12-12 13:22:27

问题


I am getting an error after assembling a simple 64 bit hello world program. I am using the following commands:

nasm -f elf64 hello.asm -o hello.o    successfull
ld -o hello.o hello -m elf_x86_64     successfull
./hello

error: Cannot execute binary file exec format error

I am executing this in a 64 bit Ubuntu Virtual Machine. I appreciate your help!


回答1:


The error:

error: Cannot execute binary file exec format error

Suggests your system can't understand the executable you are trying to run. In my comments I asked you to run uname -a so that I can find out what type of system you are running in your virtual machine. You gave the output as:

Linux dell 3.16.0-50-generic #67~14.04.1-Ubuntu SMP Fri...i686 i686 i686 GNU/LINUX

The i686 tells us this is a 32-bit version of Ubuntu, not 64-bit. Had the output included x86_64 then you would be on a 64-bit Ubuntu.

A 32-Bit OS can't directly run 64-bit applications. If you need to generate and run 64-bit code you will need to install a 64-bit Ubuntu OS.

A 64-bit Ubuntu system can be configured to allow development of 32 and 64-bit code by using multilib support. If building software with C/C++ (or just the C libraries) it might be useful to install these packages on Ubuntu:

sudo apt-get install gcc-multilib g++-multilib

Assuming you do install a 64-bit OS, the command you use to link your executable appears incorrect. You have:

nasm -f elf64 hello.asm -o hello.o    
ld -o hello.o hello -m elf_x86_64 
./hello

The NASM command looks okay. That assembles hello.asm to a 64-bit object file called hello.o . The LD command is being told to generate a 64-bit output file called hello.o from a file called hello. The commands should have looked like:

nasm -f elf64 hello.asm -o hello.o    
ld -o hello hello.o -m elf_x86_64 
./hello

Notice that we now use -o hello as we want to output an executable called hello from an object file called hello.o.




回答2:


You may have 32-bit one, check once again. Also, as help says, there are more binary formats, try following: elfx32, elf32, elf.



来源:https://stackoverflow.com/questions/34680282/nasm-on-virtual-machine-ubuntu-cannot-execute-binary-file-exec-format-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!