I am interested in executing a function which is written in C language:-
//filename "CLang.c"
#include<stdio.h>
void fun() {
printf("Hello World");
}
I want to call this fun()
through assembly language which i have written:- (NASM 64bit)
; filename "MyASM.asm"
section .data
section .bss
section .text
global _start
_start:
call fun
mov rax,60 ; exit
mov rdi,1
syscall
I have created object file by using these commands nasm -f elf64 MyAsm.asm
and gcc -c CLang.c
.
When I merge these two file with gcc gcc MyASM.o CLang.o
i get an error as
MyASM.o: In function `_start':
MyASM.asm:(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:(.text+0x0): first defined here
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
I didn't understand why it says as multiple definition of _start
I have written only one _start ???
I have no clue how to attach only gcc libraries with MyASM.o ???