编译我自己的内核(而不是从linux-kernel源代码)

我从这里跟随内核教程

即时通讯编辑我的文件有问题。

当我尝试编译时出现以下错误:

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不是我的主要语言,但我正在学习它,所以我道歉,如果我的问题很简单,但我会认为这些定义应该是相同的?

Solutions Collecting From Web of "编译我自己的内核(而不是从linux-kernel源代码)"

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

如果你正在开发你自己的内核,你会想写你自己的system.h 。 如果你正在写system.hmain.c ,你可以让它们匹配起来,不过你可以选择。 如果你看看本教程的这个页面 ,你会发现这个头文件和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 coreel Development Tutorial * By: Brandon F. (friesenb@gmail.com) * Desc: Main.c: C code entry. * * Notes: No warranty expressed or implied. Use at own risk. */ 

它看起来并不像是在试图按照教程,而是在尝试从教程中剪切和粘贴代码。 这就像试图通过一本书继续学习脑部手术一样。 你可能会得到它的工作,但如果你真的不明白你在做什么……那么,请世界帮忙,不要用它来批评任何事情。

在main.c的每个方法定义中用int替换size_t