我已经用C写了一个Hello World程序,我使用命令gcc -S -o hello.s hello.c (代码在hello.c中)来生成汇编,然后使用as来汇编它。最后,我使用ld链接了目标代码,但它给了我以下错误:
ld: a.out:hello.c:(.text+0xa): undefined reference to `__main'
ld: a.out:hello.c:(.text+0x16): undefined reference to `puts'C代码如下:
#include <stdio.h>
int main(void) {
printf("Hello world!\n");
} 我使用英特尔酷睿i3处理器,并使用MinGW进行编译。我的操作系统是Windows 7。
这是生成的程序集:
.file "hello.c"
.text
.def ___main; .scl 2; .type 32; .endef
.section .rdata,"dr"
LC0:
.ascii "Hello world!\0"
.text
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
LFB13:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
andl $-16, %esp
subl $16, %esp
call ___main
movl $LC0, (%esp)
call _puts
movl $0, %eax
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
LFE13:
.ident "GCC: (MinGW.org GCC Build-2) 9.2.0"
.def _puts; .scl 2; .type 32; .endef发布于 2020-10-15 01:34:09
感谢Nate Eldredge帮我找到了答案。
要链接as生成的文件,请使用gcc -v (file)。
https://stackoverflow.com/questions/64325336
复制相似问题