I'm getting a very frustrating problem with my linker, I try compiling and linking my very basic kernel and I get the following error from my linker:
Code: Select all
S$ make
ld -Tlink.ld -melf_i386 -o kern/kernel obj/boot.o
obj/boot.o: In function `start':
core/arch/boot.asm:(.__mbHeader+0x24): undefined reference to `kmain'
make: *** [kern/kernel] Error 1
I've also tried using the "_kmain" and then using the make parameter "-fno-leading-underscore" with the same outcome. Any idea's?
main.c:
Code: Select all
#include <system.h>
void kmain( struct multiboot *mbd, unsigned int magic )
{
return 0xDEADBEEF;
}
Code: Select all
; boot.asm -- The bootstrap for GRUB
; The Multiboot macroes for telling GRUB how to load the kernel
section .__mbHeader
MBOOT_PAGE_ALIGN equ 1<<0 ; Load everything on a page boundary
MBOOT_MEM_INFO equ 1<<1 ; Provide the kernel with the memory map
MBOOT_HEADER_MAGIC equ 0x1BADB002 ; Multiboot magic number, required by GRUB
MBOOT_HEADER_FLAGS equ MBOOT_PAGE_ALIGN | MBOOT_MEM_INFO
MBOOT_CHECKSUM equ -(MBOOT_HEADER_MAGIC + MBOOT_HEADER_FLAGS)
[bits 32]
[global mboot]
[extern code]
[extern bss]
[extern end]
mboot:
dd MBOOT_HEADER_MAGIC
dd MBOOT_HEADER_FLAGS
dd MBOOT_CHECKSUM
dd mboot
dd code
dd bss
dd end
dd start
[global start]
[extern kmain]
start:
push esp
push ebx
cli
call kmain
jmp $
Code: Select all
CPP_MAIN_SOURCE = main.c
CPP_ARCH_SOURCES =
CPP_CORE_SOURCES =
# Make sure to add the likes of the directories arch and gui etc here too!
ASM_SOURCES = boot.asm
# Here are the object files for the sources above
C_MAIN_OBJECTS = $(patsubst %.c,obj/%.o,$(C_MAIN_SOURCE))
C_ARCH_OBJECTS = $(patsubst %.c,obj/%.o,$(C_ARCH_SOURCES))
C_CORE_OBJECTS = $(patsubst %.c,obj/%.o,$(C_CORE_SOURCES))
# Make sure to add the object files for directories like "gui" etc...
ASM_OBJECTS = $(patsubst %.asm,obj/%.o,$(ASM_SOURCES))
# Flags for the C/CPP and ASM compilers, and also for the Linker
CFLAGS = -c \
-nostdlib \
-nostdinc \
-fno-builtin \
-fno-stack-protector \
-fno-leading-underscores \
-m32 \
-Iinclude \
-Wall \
-Wextra
LDFLAGS = -Tlink.ld \
-melf_i386 \
# --oformat = elf32-i386
ASFLAGS = -felf
# Compilers themselves
CC = gcc
ASC = nasm
# Now onto the compiling
all: kern/kernel
.PHONY: clean
clean:
-rm -f obj/*.o, kern/kernel
# NB: C_GUI_OBJECTS ( if its going to be called that ) will need to go in here too!
kern/kernel: $(C_MAIN_OBJECTS) $(C_ARCH_OBJECTS) $(C_CORE_OBJECTS) $(ASM_OBJECTS)
ld $(LDFLAGS) -o $@ $^
@echo "Linking Everything for kernel..."
@echo "Linking Complete..."
@echo "\n\n\nKernel is ready for use"
$(C_MAIN_OBJECTS): obj/%.o : core/%.c
$(CC) $(CFLAGS) $< -o $@
@echo "Completed main.c in \"core\""
vpath %.c core
$(C_ARCH_OBJECTS): obj/%.o : core/arch/%.c
$(CC) $(CFLAGS) $< -o $@
@echo "Completed all .c files in \"core/arch\""
vpath %.c core/arch
$(C_CORE_OBJECTS): obj/%.o : core/%.c
$(CC) $(CFLAGS) $< -o $@
@echo "Completed all .c files in \"core\""
vpath %.c core
$(ASM_OBJECTS): obj/%.o : core/arch/%.asm
$(ASC) $(ASFLAGS) $< -o $@
@echo "Completed all .asm files"
vpath %.asm core/arch