I had some code that worked fine, but then I decided to put it in a header file and now its not working. This is my first time using my own header files so I'm assuming I made a beginner mistake somewhere...

/* kernel.c */
#define SCRWIDTH 200 
#define SCRHEIGHT 1200

#include "io.h"

void kmain( void* mbd, unsigned int magic )
{
	volatile unsigned char* videoram = (volatile unsigned char *) 0xb8000;
		
	const char string[] = "Hi";

	clear(videoram);
	printstr(string, videoram);
}
/* io.h */
#ifndef IO_H
#define IO_H

extern void clear(volatile unsigned char *videoram);
extern void printstr(const char *string, volatile unsigned char *videoram);

#endif
/* io.c */
void clear(volatile unsigned char *videoram)
{
	int i, j;
	for(i = 0; i < SCRHEIGHT; i++)
	{
		for(j = 0; j < SCRWIDTH; j++)
		{
			videoram[2*i] = 32;
			videoram[1+(2*i)] = 0x07;
		}
	}
}

void printstr(const char *string, volatile unsigned char *videoram)
{
	int i = 0;
	while(string[i] != '\0')
	{
		videoram[2*i] = string[i]; 
		videoram[1+(2*i)] = 0x07;
		i++;
	}
}

It compiles fine, but I'm getting the error from my linker:
kernel.c:(.text+0x1e): undefined reference to `clear'
kernel.c:(.text+0x30): undefined reference to `printstr'

I'm using gcc as my compiler and LD as my linker.

Recommended Answers

All 2 Replies

You need to show your compiler and link commands.

Some additions:
1. At any case don't name your .h file as io.h: there is (non-standard) system header io.h (low-level file handling) in most of C implementations. It's not an error (system header is <io.h> ), but...
2. No need in extern keyword in function prototypes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.