Anyway I came here to ask a question
My OS And Tools of choice
Windows XP Pro SP2
G++
ld-elf
bochs
None of this code is deadlly serious, It's just to make sure my environment is working right!
I have my main.cpp:
Code: Select all
#include "VGA.h"
extern "C" void __cxa_pure_virtual()
{
// print error message
}
extern "C" void kmain(void* mbd, unsigned int magic);
void kmain( void* mbd, unsigned int magic )
{
VGA v;
v.clrscr();
}
and my VGA.h
Code: Select all
#ifndef VGA_H
#define VGA_H
class VGA
{
private:
char *videoMemory;
public:
VGA();
~VGA();
void clrscr();
};
#endif
and my VGA.cpp
Code: Select all
#include "VGA.h"
VGA::VGA()
{
videoMemory = (char*) 0xb8000;
}
VGA::~VGA()
{
}
void VGA::clrscr()
{
int i;
for(i=0;i < (80*25*2);i+=2)
{
videoMemory[i]=' ';
videoMemory[i+1]=0x07;
}
}
Now If I compile with:
Code: Select all
"Build Tools\MinGW\bin\g++" -fno-exceptions -fno-rtti -o "Output\object\kernel.o" -c -nostdlib -nostartfiles -nodefaultlibs "Source\Kernel\main.cpp" "Source\Kernel\VGA.cpp"
G++ Throws:
Source\Kernel\main.cpp:15: sorry, unimplemented: inter-module optimisations not implemented yet In file included from Source\Kernel\VGA.cpp:1:
Source\Kernel\VGA.h:5: error: redefinition of `class VGA'
Source\Kernel\VGA.h:5: error: previous definition of `class VGA'
my external linking (With LD-elf) throws:
Output\object\kernel.o(.text+0x13):main.cpp: undefined reference to `__ZN3VGAC1Ev'
Output\object\kernel.o(.text+0x1e):main.cpp: undefined reference to `__ZN3VGA6clrscrEv'
Output\object\kernel.o(.text+0x29):main.cpp: undefined reference to `__ZN3VGAD1Ev'
Yet If I add "#include "VGA.cpp"" to main.CPP, like so:
Code: Select all
#include "VGA.cpp"
#include "VGA.h"
extern "C" void __cxa_pure_virtual()
{
// print error message
}
extern "C" void kmain(void* mbd, unsigned int magic);
void kmain( void* mbd, unsigned int magic )
{
VGA v;
v.clrscr();
}
And compile with:
Code: Select all
"Build Tools\MinGW\bin\g++" -fno-exceptions -fno-rtti -o "Output\object\kernel.o" -c -nostdlib -nostartfiles -nodefaultlibs "Source\Kernel\main.cpp"
It will compile correctly and will even boot in bochs (And will do what I expected, Clear the screen)!
But Including CPP files isn't exactly right is it?
Any Ideas on how to resolve this would be MUCH appreciated! - Maybe I am overlooking something I need to do to get this working (Maybe I'm doing my G++ command TOTALLY wrong)