Issues linking JamesM tutorial
Posted: Sat Mar 24, 2012 7:56 pm
Okay.. looks like I'm back here to ask stupid questions. My project so far is a mix of JamesM's tutorials and Bran's tutorials, after adding the heap code and fixing typos I'm getting linker errors saying that 'kernel_directory' and 'current_directory' have been defined multiple times.If I don't include "paging.h" from my main file one set of the messages disappears, but I've got ifdef guards and I don't understand why I'm getting them at all. Looking into "kheap.c" and "paging.c" they each have an include for the others header file, and I'm wondering if this could be part of the issue. Both 'kernel_directory' and 'current_directory' are declared in "paging.h". I'm almost positive I'm overlooking something stupid, help would be much appreciated.
Linker messages:
paging.c
kheap.h
kheap.c
Linker messages:
paging.hld -Tlink.ld -o kernel boot.o main.o common.o screen.o gdt.o idt.o isrs.o irq.o timer.o kb.o kheap.o paging.o ordered_array.o
kheap.o:(.bss+0x0): multiple definition of `kernel_directory'
main.o:(.bss+0x0): first defined here
kheap.o:(.bss+0x4): multiple definition of `current_directory'
main.o:(.bss+0x4): first defined here
paging.o:(.bss+0x0): multiple definition of `kernel_directory'
main.o:(.bss+0x0): first defined here
paging.o:(.bss+0x4): multiple definition of `current_directory'
main.o:(.bss+0x4): first defined here
make: *** [link] Error 1
Code: Select all
// paging.h -- Defines the interface for and structures relating to paging.
// Written for JamesM's kernel development tutorials.
#ifndef PAGING_H
#define PAGING_H
#include <system.h>
#include <common.h>
//...
// The kernel's page directory
page_directory_t *kernel_directory=0;
// The current page directory;
page_directory_t *current_directory=0;
//...
#endif
Code: Select all
// paging.c -- Defines the interface for and structures relating to paging.
// Written for JamesM's kernel development tutorials.
#include "paging.h"
#include "kheap.h"
// A bitset of frames - used or free.
u32int *frames;
u32int nframes;
// Defined in kheap.c
extern u32int placement_address;
extern heap_t* kheap;
//...
Code: Select all
// kheap.h -- Interface for kernel heap functions, also provides
// a placement malloc() for use before the heap is
// initialised.
// Written for JamesM's kernel development tutorials.
#ifndef KHEAP_H
#define KHEAP_H
#include "common.h"
#include "ordered_array.h"
#define KHEAP_START 0xC0000000
#define KHEAP_INITIAL_SIZE 0x100000
#define HEAP_INDEX_SIZE 0x20000
#define HEAP_MAGIC 0x123890AB
#define HEAP_MIN_SIZE 0x70000
//declarations ...
#endif // KHEAP_H
Code: Select all
// kheap.c -- Kernel heap functions, also provides
// a placement malloc() for use before the heap is
// initialised.
// Written for JamesM's kernel development tutorials.
#include "kheap.h"
#include "paging.h"
// end is defined in the linker script.
extern u32int end;
u32int placement_address = (u32int)&end;
extern page_directory_t *kernel_directory;
heap_t *kheap=0;
//implementations...