2016-10-28 3 views
5

यह कोड: लिनक्स कर्नेल मॉड्यूल जो सीधे आपके पीएस/2 कीबोर्ड (न्यू लॉक, कैप्स लॉक, और स्क्रॉल लॉक) के एल ई डी को नियंत्रित करता है)कर्नेल मॉड्यूल कंपाइलर त्रुटि: फ़ंक्शन घोषणा प्रोटोटाइप नहीं है [-Werror = सख्त प्रोटोटाइप]

#include <linux/module.h> 
#include <linux/kernel.h> 

int check_bit(unsigned char status, int i) { 
    return (status & (1<<(i))); 
} 

unsigned char kbd_read_status() { // <== ERROR first appears on this line 
    return inb(0x64); 
} 

unsigned char kbd_read_data() { 
    unsigned char status; 
    do 
    { 
     status = kbd_read_status(); 
    } 
    while(!check_bit(status, 0)); 
    return inb(0x60); 
} 

जब चलाने makefile:

make -C /lib/modules/3.19.0-15-generic/build M=/home/fyousry/Desktop/hellokernel modules 
make[1]: Entering directory '/usr/src/linux-headers-3.19.0-15-generic' 
    CC [M] /home/fyousry/Desktop/hellokernel/New.o 
/home/fyousry/Desktop/hellokernel/New.c:9:15: error: function declaration isn’t a prototype [-Werror=strict-prototypes] 
unsigned char kbd_read_status() { 
      ^
/home/fyousry/Desktop/hellokernel/New.c:13:15: error: function declaration isn’t a prototype [-Werror=strict-prototypes] 
unsigned char kbd_read_data() { 
      ^
cc1: some warnings being treated as errors 
scripts/Makefile.build:263: recipe for target '/home/fyousry/Desktop/hellokernel/New.o' failed 
make[2]: *** [/home/fyousry/Desktop/hellokernel/New.o] Error 1 
Makefile:1394: recipe for target '_module_/home/fyousry/Desktop/hellokernel' failed 
make[1]: *** [_module_/home/fyousry/Desktop/hellokernel] Error 2 
make[1]: Leaving directory '/usr/src/linux-headers-3.19.0-15-generic' 
Makefile:3: recipe for target 'all' failed 
make: *** [all] Error 2 

जब ऐड # शामिल 'sys/io.h' इस त्रुटि शो

make -C /lib/modules/3.19.0-15-generic/build M=/home/fyousry/Desktop/hellokernel modules 
make[1]: Entering directory '/usr/src/linux-headers-3.19.0-15-generic' 
    CC [M] /home/fyousry/Desktop/hellokernel/New.o 
/home/fyousry/Desktop/hellokernel/New.c:3:21: fatal error: sys/uio.h: No such file or directory 
#include <sys/io.h> 
        ^
compilation terminated. 
scripts/Makefile.build:263: recipe for target '/home/fyousry/Desktop/hellokernel/New.o' failed 
make[2]: *** [/home/fyousry/Desktop/hellokernel/New.o] Error 1 
Makefile:1394: recipe for target '_module_/home/fyousry/Desktop/hellokernel' failed 
make[1]: *** [_module_/home/fyousry/Desktop/hellokernel] Error 2 
make[1]: Leaving directory '/usr/src/linux-headers-3.19.0-15-generic' 
Makefile:3: recipe for target 'all' failed 
make: *** [all] Error 2 
+2

बस एक अनुमान है, लेकिन क्या आपको इसे खाली छोड़ने के बजाय, अपने पैरामीटर के लिए एक स्पष्ट 'kbd_read_status (शून्य)' की आवश्यकता है? 'kbd_read_status()' – abelenky

+0

धन्यवाद @abelenky। यह काम –

+0

पोस्ट कोड में फ़ंक्शंस के प्रोटोटाइप गुम हैं: 'हस्ताक्षरित char kbd_read_status()' और फ़ंक्शन: 'हस्ताक्षरित char kbd_read_data() '। सुझाव दें कि आप उन प्रोटोटाइप को अपनी स्रोत फ़ाइल में जोड़कर शुरू करें – user3629249

उत्तर

8

एक उचित प्रोटोटाइप के लिए, आप अपनी पैरामीटर सूची खाली नहीं छोड़ सकते हैं।
यदि आपका फ़ंक्शन कोई पैरामीटर नहीं लेता है, तो आपको यह निर्दिष्ट करना होगा कि यह (void) है।

kbd_read_status(void) बजाय kbd_read_status()

कर्नेल कोड भी बहुत कुछ पंडिताऊ इस बारे में है।
अन्य कोड में, आप खाली पैरामीटर से दूर हो सकते हैं, लेकिन सबसे सख्त नियमों के तहत नहीं।

संबंधित मुद्दे