2009-11-06 150 views
3

我从以下编译我的文件here编译我自己的内核(而不是从Linux内核源)

的具有1M的问题内核教程。

我碰到下面的错误,当我试图编译:

main.c:8: error: expected declaration specifiers or ‘...’ before ‘size_t’ 
main.c:8: error: conflicting types for ‘memcpy’       
./include/system.h:5: note: previous declaration of ‘memcpy’ was here  
main.c: In function ‘memcpy’:            
main.c:12: error: ‘count’ undeclared (first use in this function)   
main.c:12: error: (Each undeclared identifier is reported only once  
main.c:12: error: for each function it appears in.)      
main.c: At top level:              
main.c:16: error: expected declaration specifiers or ‘...’ before ‘size_t’ 
main.c:16: error: conflicting types for ‘memset’ 
./include/system.h:6: note: previous declaration of ‘memset’ was here 
main.c: In function ‘memset’: 
main.c:19: error: ‘count’ undeclared (first use in this function) 
main.c: At top level: 
main.c:23: error: expected declaration specifiers or ‘...’ before ‘size_t’ 
main.c:23: error: conflicting types for ‘memsetw’ 
./include/system.h:7: note: previous declaration of ‘memsetw’ was here 
main.c: In function ‘memsetw’: 
main.c:26: error: ‘count’ undeclared (first use in this function) 
main.c: At top level: 
main.c:30: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘strlen’ 
main.c:49: warning: return type of ‘main’ is not ‘int’ 
main.c: In function ‘main’: 
main.c:64: warning: pointer targets in passing argument 1 of ‘puts’ differ in signedness 
./include/system.h:13: note: expected ‘unsigned char *’ but argument is of type ‘char *’ 
main.c:51: warning: unused variable ‘i’ 
scrn.c: In function ‘scroll’: 
scrn.c:24: warning: passing argument 1 of ‘memcpy’ from incompatible pointer type 
./include/system.h:5: note: expected ‘unsigned char *’ but argument is of type ‘short unsigned int *’ 
scrn.c:24: warning: passing argument 2 of ‘memcpy’ from incompatible pointer type 
./include/system.h:5: note: expected ‘const unsigned char *’ but argument is of type ‘short unsigned int *’ 
scrn.c: In function ‘puts’: 
scrn.c:139: warning: pointer targets in passing argument 1 of ‘strlen’ differ in signedness 
./include/system.h:8: note: expected ‘const char *’ but argument is of type ‘unsigned char *’ 

我的文件是从教程中的的精确副本。
我可以看到,在main.c中的函数定义,像这样

void *memcpy(void *dest,const void *src, size_t count)

但在我system.h中文件它们像这样

extern unsigned char *memcpy(unsigned char *dest,const unsigned char *src, int count)

C中定义不是我主要的语言,但我正在学习它的过程中,所以我道歉,如果我的问题很简单,但我会认为这些定义应该是相同的?

+4

不是一个真正的回答你的问题的size_t,但我不建议学习C和学习内核的开发都在同一个镜头。在开始尝试编写自己的内核之前,先用C语言做一些用户空间工作! – 2009-11-06 18:11:51

+0

我明白你的观点。该教程非常简单,我明白它在做什么。我的主要困惑是为什么这些文件无法从教程中编译。当您从教程中拉取代码时,您会认为像函数类型声明这样的东西不会成为问题! – 2009-11-06 18:15:44

+1

我不太确定你确实明白它在做什么。如果C不是您的主要语言,您是否花了很多时间在目标平台上使用汇编语言工作?因为如果你还没有完成C语言或汇编语言,那么我很难想象你可以完全遵循内核应该做的事情。 – 2009-11-06 18:28:58

回答

5

可能是您的问题size_t与您的平台上的int不一样,或者size_t没有正确指定。指针类型应该是OK的(技术上,它们也应该匹配,但是在大多数系统上sizeof(char*) == sizeof(void*))。

如果您正在开发自己的内核,那么您需要编写自己的system.h。如果您同时编写system.hmain.c,则可以根据需要将它们匹配起来。如果你看一下this page of the tutorial,你会看到标题和C源都声明memcpy为:

unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count); 

但是,如果你下载示例源文件在教程的最后,你会发现它是不是:

void *memcpy(void *dest, const void *src, size_t count); 

望着那文件的顶部,你会发现这样的评论:

/* bkerndev - Bran's Kernel Development Tutorial 
* By: Brandon F. ([email protected]) 
* Desc: Main.c: C code entry. 
* 
* Notes: No warranty expressed or implied. Use at own risk. */ 

它看起来并不像你想跟随的教程,但RA那么你试图从教程中剪切和粘贴代码。这就像试图通过一本书一起学习进行脑部手术一样。你可能会得到它的工作,但如果你真的不明白你在做什么...好吧,请为世界帮忙,不要用它来做任何关键的事情。

+0

大声笑。以及它更像是在尝试使用教程来了解内核如何更好地工作,但是因为我不知道C im的所有细节都被迫仅仅使用已经提供的代码。感谢您的建议! – 2009-11-06 18:29:14

-1

在每个方法定义为int替换上的main.c

+3

因为aswer已经被提供并且被接受..在稍后提供相同的答案(再次)是没有意义的... :)尝试着重于没有答案的问题;) – 2011-07-29 22:05:34

+1

同意。另外,不要只为您的答案提供代码。解释为什么**。 – 2012-11-15 23:48:31