编译我自己的内核(不是来自linux-kernel源)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了编译我自己的内核(不是来自linux-kernel源),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3700字,纯文字阅读大概需要6分钟。
内容图文
![编译我自己的内核(不是来自linux-kernel源)](/upload/InfoBanner/zyjiaocheng/947/dc4b9b1ab7bd49b293b0aba7cf53afae.jpg)
我正在关注here的内核教程
我在编译文件时遇到问题.
尝试编译时出现以下错误:
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不是我的主要语言,但我正在学习它,因此,如果我的问题很简单,我会道歉,但我认为这些定义应该相同吗?
解决方法:
可能是您的问题是size_t与平台上的int不同,或者根本没有正确指定size_t.指针类型应该确定(从技术上讲,它们也应该匹配,但是在大多数系统上,sizeof(char *)== sizeof(void *)).
如果您正在开发自己的内核,则需要编写自己的system.h.如果您同时编写system.h和main.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. (friesenb@gmail.com)
* Desc: Main.c: C code entry.
*
* Notes: No warranty expressed or implied. Use at own risk. */
看起来您似乎不想按照本教程进行操作,而是要像从教程中剪切并粘贴代码一样.就像试图通过跟随一本书来学习进行脑外科手术一样.您可能会使其正常工作,但是如果您真的不了解自己在做什么……好吧,请帮个忙,不要将其用于任何重要的事情.
内容总结
以上是互联网集市为您收集整理的编译我自己的内核(不是来自linux-kernel源)全部内容,希望文章能够帮你解决编译我自己的内核(不是来自linux-kernel源)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。