I cannot combine my kernel_entry.asm and main.c. My main.c calls an asm function Sum
. Both nasm and gcc compiles respective files. However, the linker gives an error.
Kernel_entry.asm:
[bits 32]
[extern _start]
[global _Sum]
....
_Sum:
push ebp
mov ebp, esp
mov eax, [ebp+8]
mov ecx, [ebp+12]
add eax, ecx
pop ebp
ret
main.c:
....
extern int Sum();
void start() {
....
int x = Sum(4, 5);
....
}
To compile source files, I use following commands:
nasm kernel_entry.asm -f win32 -o kernel_entry.o
gcc -ffreestanding -c main.c -o main.o
....
ld -T NUL -o kernel.tmp -Ttext 0x1000 kernel_entry.o main.o mem.o port_in_out.o screen.o idt.o
Linker gives following error:main.o:main.c:(.text+0xa82): undifened reference to 'Sum'
. I tried everything but couldn't find any solution. When I remove asm function call from main.c, it works.
gcc -m32
did not work for me. I am working on a Windows computer. Maybe that is the reason? – user2972185nasm kernel_entry.asm -f elf -o kernel_entry.o
did it for me – rfernandes