0
我正在學習os教程。這裏是我的代碼:在NASM使用ld將三個目標文件鏈接到二進制文件時發生鏈接錯誤
裝載機
; Loader.asm
bits 32
extern _main
global start
start:
call _main ; Call our kernel's main() function
cli ; Stop interrupts (thats another article?)
hlt ; Stop all instructions
我的C代碼
//main.c
int main(void)
{
puts("Hello, world!"); /* Print our welcome message */
for(;;); /* Keep the OS running */
}
/* video.c */
int x, y; /* Our global 'x' and 'y' */
char color; /* Our global color attribute */
void putc(unsigned char c)
{
char *vidmem = (char*)0xB8000; /* pointer to video memory */
int pos = (y * 2) + x; /* Get the position */
vidmem[pos] = c; /* print the character */
vidmem[pos++] = color; /* Set the color attribute */
if (c == '\n') // newline
{
y++;
x = 0;
}
else
x += 2; // 2 bytes per char
}
int puts(char *message)
{
int length;
while(*message)
{
putc(*message++);
length++;
}
return length;
}
我通過運行編譯的這些:
gcc -ffreestanding -fno-builtin -nostdlib -c *.c // (that's main.c and video.c)
nasm -f aout loader.asm -o loader.o
我能成功編譯,當我嘗試使用ld將它們鏈接到bin文件中,顯示錯誤:
ld: error: loader.o:1:1: invalid character
我在做什麼錯?
什麼是ld命令行? –