2009-11-06 151 views
3

我從以下編譯我的文件here編譯我自己的內核(而不是從Linux內核源)

的具有1M的問題內核教程。

我碰到下面的錯誤,當我試圖編譯:

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中定義不是我主要的語言,但我正在學習它的過程中,所以我道歉,如果我的問題很簡單,但我會認爲這些定義應該是相同的?

+4

不是一個真正的回答你的問題的size_t,但我不建議學習C和學習內核的開發都在同一個鏡頭。在開始嘗試編寫自己的內核之前,先用C語言做一些用戶空間工作! – 2009-11-06 18:11:51

+0

我明白你的觀點。該教程非常簡單,我明白它在做什麼。我的主要困惑是爲什麼這些文件無法從教程中編譯。當您從教程中拉取代碼時,您會認爲像函數類型聲明這樣的東西不會成爲問題! – 2009-11-06 18:15:44

+1

我不太確定你確實明白它在做什麼。如果C不是您的主要語言,您是否花了很多時間在目標平臺上使用匯編語言工作?因爲如果你還沒有完成C語言或彙編語言,那麼我很難想象你可以完全遵循內核應該做的事情。 – 2009-11-06 18:28:58

回答

5

可能是您的問題size_t與您的平臺上的int不一樣,或者size_t沒有正確指定。指針類型應該是OK的(技術上,它們也應該匹配,但是在大多數系統上sizeof(char*) == sizeof(void*))。

如果您正在開發自己的內核,那麼您需要編寫自己的system.h。如果您同時編寫system.hmain.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. ([email protected]) 
* Desc: Main.c: C code entry. 
* 
* Notes: No warranty expressed or implied. Use at own risk. */ 

它看起來並不像你想跟隨的教程,但RA那麼你試圖從教程中剪切和粘貼代碼。這就像試圖通過一本書一起學習進行腦部手術一樣。你可能會得到它的工作,但如果你真的不明白你在做什麼...好吧,請爲世界幫忙,不要用它來做任何關鍵的事情。

+0

大聲笑。以及它更像是在嘗試使用教程來了解內核如何更好地工作,但是因爲我不知道C im的所有細節都被迫僅僅使用已經提供的代碼。感謝您的建議! – 2009-11-06 18:29:14

-1

在每個方法定義爲int替換上的main.c

+3

因爲aswer已經被提供並且被接受..在稍後提供相同的答案(再次)是沒有意義的... :)嘗試着重於沒有答案的問題;) – 2011-07-29 22:05:34

+1

同意。另外,不要只爲您的答案提供代碼。解釋爲什麼**。 – 2012-11-15 23:48:31