Can't compile asm hello world with gcc

前端 未结 1 981
醉话见心
醉话见心 2021-01-21 21:49

This is the code in hello.s

.data                         

hello_str:                    
    .string \"Hello, world!\\n\"


    .set hello_str         


        
相关标签:
1条回答
  • 2021-01-21 22:40

    You're trying to compile i386 code in amd64 mode, which doesn't work. Try this instead:

    gcc -m32 hellos. -o hello
    

    ...to force i386 mode.

    Edit: I recognised this because I know what i386 and amd64 code looks like, but a better clue is in the relocation name, R_X86_64_32. X86_64 is another name for the amd64 architecture; so what this is saying is that it's a 32 bit relocation for the X86_64 architecture. Given that you're not writing code for that architecture, that's a reasonable sign that it's the wrong compiler.

    0 讨论(0)
提交回复
热议问题