[英]compiling my own kernel (not from linux-kernel source)
I'm following the kernel tutorial from here 我从这里开始关注内核教程
im having problems compiling my files. 我在编译文件时遇到问题。
i get the following errors when i try to compile: 我尝试编译时遇到以下错误:
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 *’
My files are exact copies of the ones from the tutorial. 我的文件是教程中的文件的精确副本。
I can see that in main.c the functions are defined like so 我可以看到在main.c中,函数的定义是这样的
void *memcpy(void *dest,const void *src, size_t count)
but in my system.h file they are defined like so 但在我的system.h文件中,它们的定义是这样的
extern unsigned char *memcpy(unsigned char *dest,const unsigned char *src, int count)
C is not my primary language but i am in the process of learning it so I apologize if my question is simple but I would think that these definitions should be the same not? C不是我的主要语言,但我正在学习它,所以如果我的问题很简单,我会道歉,但我认为这些定义应该是相同的吗?
Probably your issue is that size_t
isn't the same as int
on your platform, or size_t
isn't specified correctly at all. 可能你的问题是
size_t
与平台上的int
,或者根本没有正确指定size_t
。 The pointer types should be OK (technically, they should match too, but on most systems sizeof(char*) == sizeof(void*)
). 指针类型应该没问题(从技术上讲,它们也应该匹配,但在大多数系统上
sizeof(char*) == sizeof(void*)
)。
If you're developing your own kernel, you'd want to write your own system.h
. 如果您正在开发自己的内核,那么您需要编写自己的
system.h
。 If you're writing both system.h
and main.c
, you can make them match up however you'd like. 如果您正在编写
system.h
和main.c
,那么您可以根据需要将它们匹配起来。 If you look at this page of the tutorial , you'd see that header and C source both declare memcpy
as: 如果您查看本教程的这一页 ,您会看到标题和C源都将
memcpy
声明为:
unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count);
But if you download the example source files at the end of the tutorial, you find it is instead: 但是,如果您在本教程结束时下载示例源文件,则会发现它是:
void *memcpy(void *dest, const void *src, size_t count);
Looking at the top of that file, you find the following comment: 查看该文件的顶部,您会找到以下注释:
/* bkerndev - Bran's Kernel Development Tutorial
* By: Brandon F. (friesenb@gmail.com)
* Desc: Main.c: C code entry.
*
* Notes: No warranty expressed or implied. Use at own risk. */
It doesn't look like you're trying to follow a tutorial, but rather that you're trying to cut and paste code from a tutorial. 它看起来并不像您正在尝试遵循教程,而是您尝试从教程中剪切和粘贴代码。 That's like trying to learn to perform brain surgery by following along in a book.
这就像试图通过跟随书中学习进行脑部手术一样。 You might get it to work, but if you don't really understand what you're doing... well, please do the world a favor and don't use it for anything critical.
你可能会让它发挥作用,但如果你真的不明白你在做什么......好吧,请帮助世界,不要把它用于任何关键的事情。
在main.c上的每个方法定义中用size替换size_t
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.