Gcc nasm.c和.asm文件链接

Gcc nasm.c和.asm文件链接,gcc,assembly,nasm,Gcc,Assembly,Nasm,我正在尝试链接一个c程序和一个.asm文件(nasm)。 从一个简单的程序开始打印helloworld,我甚至无法做到这一点。编码和编译步骤如下所示: hello.asm文件 extern sample section .text global main main: call sample mov eax,1 mov ebx,0 int 80h c文件 #include<stdio.h> void sample() { printf("Hello world")

我正在尝试链接一个c程序和一个.asm文件(nasm)。 从一个简单的程序开始打印helloworld,我甚至无法做到这一点。编码和编译步骤如下所示:

hello.asm文件

extern sample    

section .text
global main
main:

call sample
mov eax,1
mov ebx,0
int 80h
c文件

#include<stdio.h>
void sample()
{
    printf("Hello world");
}

我试着在网上寻找解决方案,但找不到。有人能帮我继续吗?

你把事情搞得一团糟。什么是
fib.o
?您有
hello.asm
您可能想要
hello.o
在那里。错误还表明您在
cfile.c
中定义了
main
,请仔细检查源文件。@Jester抱歉。现在更正这些。是的,有一个主要功能。我现在把它拆了。完成了编译部分。但是没有输出。看,现在好多了!好的,您不应该在asm中使用exit syscall,因为这不会正确关闭c库。您只需
ret
,或使用
呼叫退出
。然后您将看到输出。如果将
\n
添加到
printf
中,您可能也会看到它,因为输出是行缓冲的。@Jester非常感谢..它现在起作用了:)
jincy@jincy:~/codes/nasm$ nasm -f elf64 hello.asm
jincy@jincy:~/codes/nasm$ gcc -c cfile.c
jincy@jincy:~/codes/nasm$ gcc cfile.o hello.o
jincy@jincy:~/codes/nasm$ ./a.out
jincy@jincy:~/codes/nasm$