Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
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:
ld -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
// 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
// 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;
//...
// 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...
Last edited by sdfkjsdfkj on Sat Mar 24, 2012 8:32 pm, edited 1 time in total.
Can you trim it down a bit to where you think the issue may be? Imho this is too much to expect people to read, what have you already tried yourself in debugging and troubleshooting?
*facepalm* Sorry about that, somehow I managed to forget how large the files actually were. So far I've removed the include from main (which removed one of the sets of messages), moved the include paging.h from kheap.c into kheap,h (nothing changed), mover kernel_directory and current_directory into paging.c out of the header (nothing changed), and moved the include for kheap.h inside paging.c into paging.h (nothing changed). I considered removing the include for kheap.h inside paging.c, and externing all the required things from kheap but figured that kinda makes the header file useless if I have to do that everywhere I need kheap stuff.
You're defining the variable inside of the header when you just want to have a forward declaration. Add the extern keyword inside of the header to tell the compiler that the variable will be resolved by the linker at link time, and also define it in a .c file.