在 x64 linux 上编译 x86 程序集的问题 [英] Problems compiling x86 assembly on x64 linux

查看:37
本文介绍了在 x64 linux 上编译 x86 程序集的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 x64 ubuntu 上编译用 X86 编写的汇编代码,但出现以下错误:

I tried compiling assembly code written in X86 on a x64 ubuntu, and got the following errors:

gcc -m32 -o T Tirgul3b_Hello.s
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status

这是我尝试编译的代码:

This is the code I tried to compile:

    #This is a simple "Hello World!" program
    .section    .rodata #read only data section
str:    .string "Hello World!\n"
    ########
    .text   #the beginnig of the code
.globl  main    #the label "main" is used to state the initial point of this program
    .type   main, @function # the label "main" representing the beginning of a function
main:   # the main function:
    pushl   %ebp        #save the old frame pointer
    movl    %esp,   %ebp    #create the new frame pointer

    pushl   $str        #the string is the only paramter passed to the printf function.
    call    printf      #calling to printf AFTER we put its parameters in the stack.

    #return from printf:
    movl    $0, %eax    #return value is zero (just like in c - we tell the OS that this program finished seccessfully)
    movl    %ebp,   %esp    #restore the old stack pointer - release all used memory.
    popl    %ebp        #restore old frame pointer (the caller function frame)
    ret         #return to caller function (OS)

我在这里遗漏了什么,我该如何解决?

What am I missing here and how do I fix it?

如果您需要任何额外信息,请在评论中询问.

If there is any extra information you need, ask in comments.

推荐答案

正如 Michael Petch 所说,安装 gccg++ multilib 库成功了.我安装了:

As Michael Petch said, installing the gcc and g++ multilib libraries did the trick. I installed with:

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

这篇关于在 x64 linux 上编译 x86 程序集的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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