编译我自己的内核(而不是从Linux内核源代码) [英] compiling my own kernel (not from linux-kernel source)
问题描述
我下面从内核教程这里
有我的编译文件的问题IM。
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 *’
我的文件是从教程中的的精确副本。结果
我可以看到,在main.c中的功能,像这样定义
My files are exact copies of the ones from the tutorial.
I can see that in main.c the functions are defined like so
无效*的memcpy(void *的DEST,常量无效* SRC,为size_t计数)
但在我system.h中的文件他们像这样定义
but in my system.h file they are defined like so
的extern unsigned char型*的memcpy(无符号字符* DEST,const的无符号字符* SRC,诠释计数)
C不是我的主要语言,但我在学习它的过程,所以我道歉,如果我的问题很简单,但我认为,这些定义应该是一样的呢?
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?
推荐答案
也许你的问题是,为size_t
是不一样的 INT
你的平台上,或为size_t
未正确指定的。指针类型应行(从技术上讲,他们应该匹配过,但在大多数系统的sizeof(字符*)==的sizeof(无效*)
)。
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. The pointer types should be OK (technically, they should match too, but on most systems sizeof(char*) == sizeof(void*)
).
如果您正在开发自己的内核,你想要编写自己的 system.h中
。如果你正在写两个 system.h中
和的main.c
,你可以让它们却匹配,你会喜欢。如果你看一下教程的这个页面,你会发现头部和C源代码都声明的memcpy
为:
If you're developing your own kernel, you'd want to write your own system.h
. If you're writing both system.h
and main.c
, you can make them match up however you'd like. If you look at this page of the tutorial, you'd see that header and C source both declare memcpy
as:
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. */
它看起来并不像你想跟随的教程,而是你正试图从一个教程剪切和粘贴code。这就像努力学习沿在一本书下进行脑部手术。你可能会得到它的工作,但如果你真的不明白你在做什么......嗯,请做世界一个忙,不使用它的任何东西的关键。
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.
这篇关于编译我自己的内核(而不是从Linux内核源代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!