use*_*075 3 assembly x86-64 nasm virtual-machine ld
在组装一个简单的64位hello world程序后,我收到一个错误.我使用以下命令:
nasm -f elf64 hello.asm -o hello.o successfull
ld -o hello.o hello -m elf_x86_64 successfull
./hello
Run Code Online (Sandbox Code Playgroud)
错误:无法执行二进制文件exec格式错误
我在64位Ubuntu虚拟机中执行此操作.我感谢您的帮助!
错误:
错误:无法执行二进制文件exec格式错误
建议您的系统无法理解您尝试运行的可执行文件.在我的评论中,我要求您运行,uname -a以便我可以找出您在虚拟机中运行的系统类型.你给出了输出:
Linux dell 3.16.0-50-generic #67~14.04.1-Ubuntu SMP Fri...i686 i686 i686 GNU/LINUX
Run Code Online (Sandbox Code Playgroud)
在i686告诉我们,这是Ubuntu的一个32位版本,而不是64位.如果包含输出,x86_64那么你将使用64位Ubuntu.
32位操作系统无法直接运行64位应用程序.如果需要生成并运行64位代码,则需要安装64位Ubuntu操作系统.
可以将64位Ubuntu系统配置为允许使用multilib支持开发32位和64位代码.如果使用C/C++(或只是C库)构建软件,在Ubuntu上安装这些软件包可能会有用:
sudo apt-get install gcc-multilib g++-multilib
Run Code Online (Sandbox Code Playgroud)
假设您安装了64位操作系统,用于链接可执行文件的命令似乎不正确.你有:
nasm -f elf64 hello.asm -o hello.o
ld -o hello.o hello -m elf_x86_64
./hello
Run Code Online (Sandbox Code Playgroud)
在NASM命令看起来不错.它汇编hello.asm为一个名为64位的目标文件hello.o.该LD命令被告知以产生称为64比特的输出文件hello.o从一个文件称为hello.命令应该看起来像:
nasm -f elf64 hello.asm -o hello.o
ld -o hello hello.o -m elf_x86_64
./hello
Run Code Online (Sandbox Code Playgroud)
请注意,我们现在使用,-o hello因为我们想要输出hello从被调用的目标文件调用的可执行文件hello.o.