1

I'm following the kernel development tutorial at osdever, and I'm at the printing to the screen portion of the tutorial. It compiles just fine, no errors or warnings, but when it goes to link, I get:

screen.o: In function `scroll':
screen.c:(.text+0x12c): undefined reference to `memcpy'
screen.o: In function `put_str':
screen.c:(.text+0x249): undefined reference to `strlen'

I do have a include statement to system.h at the top of screen.c, and in system.h I have

#ifndef __SYSTEM_H
#define __SYSTEM_H

extern unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count);
extern unsigned char *memset(unsigned char *dest, unsigned char val, int count);
extern unsigned short *memsetw(unsigned short *dest, unsigned short val, int count);
extern int strlen(const char *str);
extern unsigned char inportb (unsigned short _port);
extern void outportb (unsigned short _port, unsigned char _data);
extern void clear();
extern void put_char(unsigned char c);
extern void put_str(unsigned char *str);
extern void set_color(unsigned char fcol, unsigned char bcol);
extern void init_video();

#endif

I can't find anything about this on the web, and there's no help in the tutorial. It seems that when I change the order in the linker statement, from

/usr/local/cross/bin/i586-elf-ld -T link.ld -o kernel.bin start.o main.o screen.o

to

/usr/local/cross/bin/i586-elf-ld -T link.ld -o kernel.bin start.o screen.o main.o

I get

screen.o: In function `put_str':
screen.c:(.text+0x249): undefined reference to `strlen'
main.o: In function `main':
main.c:(.text+0x9b): undefined reference to `init_video'

Edit http://pastebin.com/ibBAVpe5 - Main.c

4
  • If you have nm, try it on the .o files. Commented Jun 29, 2011 at 1:49
  • @lhf I did, don't know what it means, but here it is:pastebin.com/mMEVf2bv Commented Jun 29, 2011 at 2:14
  • From the nm output you gave, there should not be any undefined references. BTW, T marks definitions and U marks uses. Every Uin your output is matched by a T. So my guess is that you should try putting main.o first in the list of objects, though that shouldn't be necessary. Commented Jun 29, 2011 at 2:19
  • @lhf @geekosaur Thanks for the help. I guess I'll try recompiling gcc with a different target to see if that works. Commented Jun 29, 2011 at 2:28

1 Answer 1

4

You haven't provided a strlen, so where exactly should it come from? In a normal compile, the ld command line will have an -lc added to it by cc to bring in the standard library. Given the indications that this is intended to be standalone, you will need to provide your own support routines such as strlen and memcpy; you can't use a standard C library (or would have to be very careful about it) because that will try to call into the kernel for some things.

#

That doesn't explain the other problem with reordering objects, nor the discussion in the comments below. This leads me to believe you have a broken or possibly incompatible linker script (the -T link.ld). Paste that?

Sign up to request clarification or add additional context in comments.

2 Comments

Which source file are they in? The extern lines don't count; they're promises that you do have an actual definition somewhere.
Hrm. I don't see anything wrong with that (assuming it's the format introduced by the System V ELF linker and adopted by GNU). Now I wonder about the symbol tables, or maybe odder problems such as some things compiled natively and others cross-compiled. But that's getting a little difficult to debug here....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.