2016-10-28 21 views
5

bu kod: PS/2 klavyenizin LED'lerini doğrudan kontrol eden Linux çekirdek modülü (Num Lock, Caps Lock ve Scroll Lock))kernel module derleyici hatası: function declaration bir prototip değildir [-Werror = sıkı prototip]

#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); 
} 

çalıştırılacak 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 

zaman eklenti #include 'sys/io.h' Bu hata gösterisi

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

Sadece bir tahmin, ama sadece boş bırakmak yerine, parametreleriniz için açık bir 'kbd_read_status (void)' gerekir mi? 'kbd_read_status()' – abelenky

+0

teşekkürler @abelenky. iştir –

+0

Gönderilen kodda işlevlerin prototipleri eksik: 'imzasız char kbd_read_status()' ve işlevi: 'imzasız char kbd_read_data()'. Bu prototipleri kaynak dosyanıza ekleyerek başlamanızı önerin – user3629249

cevap

8

Uygun bir prototip için parametre listenizi boş bırakamazsınız.
İşleviniz herhangi bir parametre almazsa, bunun (void) olduğunu belirtmeniz gerekir.

kbd_read_status(void) yerine kbd_read_status()

Çekirdek kod

çok daha bilgiçlik bu hakkındadır.
Diğer kodlarda boş parametrelerden kurtulabilir, ancak en katı kurallara uymazsınız.

İlgili konular