[英]compiling my own kernel (not from linux-kernel source)
我從這里開始關注內核教程
我在編譯文件時遇到問題。
我嘗試編譯時遇到以下錯誤:
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
,那么您可以根據需要將它們匹配起來。 如果您查看本教程的這一頁 ,您會看到標題和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. */
它看起來並不像您正在嘗試遵循教程,而是您嘗試從教程中剪切和粘貼代碼。 這就像試圖通過跟隨書中學習進行腦部手術一樣。 你可能會讓它發揮作用,但如果你真的不明白你在做什么......好吧,請幫助世界,不要把它用於任何關鍵的事情。
在main.c上的每個方法定義中用size替換size_t
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.