虚拟机Ubuntu上的NASM:无法执行二进制文件exec格式错误 [英] NASM on Virtual Machine Ubuntu: Cannot execute binary file exec format error

查看:1190
本文介绍了虚拟机Ubuntu上的NASM:无法执行二进制文件exec格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在组装一个简单的64位hello world程序后出现错误. 我正在使用以下命令:

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

错误:无法执行二进制文件exec格式错误

error: Cannot execute binary file exec format error

我正在64位Ubuntu虚拟机中执行此操作. 我感谢您的帮助!

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

推荐答案

错误:

错误:无法执行二进制文件exec格式错误

error: Cannot execute binary file exec format error

建议您的系统无法理解您要运行的可执行文件.在我的评论中,我要求您运行uname -a,以便我可以找到您的虚拟机中正在运行的系统类型.您给出的输出为:

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

i686告诉我们这是Ubuntu的32位版本,而不是64位.如果输出包含x86_64,那么您将使用64位Ubuntu.

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.

32位操作系统无法直接运行64位应用程序.如果需要生成和运行64位代码,则需要安装64位Ubuntu OS.

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.

可以使用 multilib 支持将64位Ubuntu系统配置为允许开发32和64位代码.如果使用C/C ++(或仅 C 库)构建软件,则在Ubuntu上安装以下软件包可能会很有用:

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


假设您确实安装了64位操作系统,则用于链接可执行文件的命令似乎不正确.你有:


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

NASM 命令看起来还不错.它将hello.asm组装为一个名为hello.o的64位目标文件.通知 LD 命令从名为hello的文件生成名为hello.o的64位输出文件.这些命令应该看起来像:

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

请注意,我们现在要使用-o hello,因为我们要从名为hello.o的对象文件中输出名为hello的可执行文件.

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

这篇关于虚拟机Ubuntu上的NASM:无法执行二进制文件exec格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆