stuman 发表于 2014-04-25 21:01

gcc中调用nasm

本帖最后由 stuman 于 2014-04-25 21:03 编辑

bar.c#include <stdio.h>
extern int f0();
main()
{
int i;
i = f0();
printf("%d",i);
}foo.asm;
global _f0
_f0:
        mov eax,100
ret
编译命令如下:
gcc -c bar.c
nasm -f elf foo.asm
gcc -o foobar bar.o foo.o

出错信息:
bar.o: In function `main':
bar.c: ( .text+0x12): undefined reference to `f0'
collect2: ld returned 1 exit status

请问如何解决?

stuman 发表于 2014-04-25 21:34

经过多次尝试,终于解决问题,要注意3点:
汇编中函数要用global导出,函数名不需要加下划线,链接目标文件时不能用ld要用gcc
页: [1]
查看完整版本: gcc中调用nasm