Chinaunix
标题:
gcc中调用nasm
[打印本页]
作者:
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
;[section .text]
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
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2