So I have two files: kernel.o(the kernel of my operating system) and libbios.o(which ported the bios interrupt to c),and ld told me : "undefined reference to 'printchar'"
.
I checked libbios.o with objdump -t and this is the result:
source/libbios.o: file format elf32-i386
SYMBOL TABLE:
00000000 l df *ABS* 00000000 include/libbios.asm
00000000 l d .TEXT 00000000 .TEXT
00000000 l .TEXT 00000000 printchar
printchar exists in the .o file.
And this is libbios.asm:
printchar:
MOV AH,0x0e
MOV AL,[ESP+4]
INT 0X10
RET
and kernel.c:
#define TRUE 1
extern void printchar(char l);
void main(){
printchar('a');
fin:
asm volatile ("hlt");
goto fin;
}
and the command line to compile kernel.o,libbios.o and link them:
i686-elf-gcc kernel.c -c -B ../i686 -o cpartofkernel.o -m16 -masm=intel -O0
nasm -O0 -felf include/libbios.asm -o libbios.o
i686-elf-ld --oformat binary libbios.o cpartofkernel.o -o kernel.bin -Ttext 0x20000000 -emain
Also this is real mode code,and because I can't find any raw binary linker in linux, I must use elf.