Page 1 of 1

Clearing the screen?

Posted: Sat Mar 07, 2009 9:44 pm
by gsingh2011
Hi, I was wondering what's wrong with this code. It compiles fine, but I get the error - kernel.c:(.text+0x1d): undefined reference to `memset'. I'm assuming it has something to do with including libraries..

Code: Select all

#include <string.h>

// Screen dimensions (for default 80x25 console)
#define LINE_PITCH 160       // line width in bytes
#define LINE_COUNT 25

void clear(volatile unsigned char* videoram)
{
    memset((void*)videoram, 0, LINE_PITCH*LINE_COUNT);
}

void kmain( void* mbd, unsigned int magic )
{
	volatile unsigned char* videoram = (volatile unsigned char *) 0xb8000;
	clear(videoram);
}

Re: Clearing the screen?

Posted: Sat Mar 07, 2009 9:48 pm
by linuxfood
Unless you wrote your 'memset', you just made beginner mistake #1.
Don't feel too bad. If you did write your own memset, make sure you're linking with the object file that contains it.

Thanks,

-B

Re: Clearing the screen?

Posted: Sat Mar 07, 2009 9:53 pm
by gsingh2011
Ah... I see. Thank you.

Re: Clearing the screen?

Posted: Sun Mar 08, 2009 6:04 am
by Combuster
#include <string.h>
If that did compile your setup is wrong already. You should not be able to include files that you have not written yourself.

Re: Clearing the screen?

Posted: Sun Mar 08, 2009 11:53 pm
by Steve the Pirate
Combuster wrote:
#include <string.h>
If that did compile your setup is wrong already. You should not be able to include files that you have not written yourself.
That's the reason it did compile - the function is declared in string.h, but he hasn't implemented it, so he gets a linker error instead of a compiler error.