开发者

Linker not recognizing extern statement

开发者 https://www.devze.com 2023-03-16 13:58 出处:网络
I\'m following the kernel development tutorial at开发者_如何学JAVA 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 go

I'm following the kernel development tutorial at开发者_如何学JAVA 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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号