首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在x64 linux上编译x86程序集的问题

在x64 linux上编译x86程序集的问题
EN

Stack Overflow用户
提问于 2015-12-18 00:07:17
回答 1查看 582关注 0票数 0

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

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 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)

我在这里遗漏了什么?我如何修复它?

如果你需要任何额外的信息,请在评论中询问。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-18 06:33:31

正如Michael Petch所说,安装gccg++ multilib库做到了这一点。我安装时使用:

sudo apt-get install gcc-multilib g++-multilib
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34339130

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档