ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

编译我自己的内核(不是来自linux-kernel源)

2019-11-07 01:50:33  阅读:122  来源: 互联网

标签:kernel c-3 linux


我正在关注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. */

看起来您似乎不想按照本教程进行操作,而是要像从教程中剪切并粘贴代码一样.就像试图通过跟随一本书来学习进行脑外科手术一样.您可能会使其正常工作,但是如果您真的不了解自己在做什么……好吧,请帮个忙,不要将其用于任何重要的事情.

标签:kernel,c-3,linux
来源: https://codeday.me/bug/20191107/2002445.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有