看板 LinuxDev 關於我們 聯絡資訊
Dear All: 請教有關編譯一個簡單的模組的問題,以下是我的程式碼: ******************************************************** hello.c: #include <linux/module.h> #if defined(CONFIG_SMP) #define __SMP__ #endif #if defined(CONFIG_MODVERSIONS) #define MODVERSIONS #include <linux/modversions.h> #endif #include <linux/kernel.h> int init_module(void) { printk(KERN_DEBUG "Hello, kernel!\n"); return 0; } void cleanup_module(void) { printk(KERN_DEBUG "Good-bye, kernel!\n"); } ************************************************************** Makefile: # standards INCLUDE = /usr/src/kernels/2.6.18-1.2798.fc6-i686/hello CC = gcc CFLAGS = -D__KERNEL__ -I$(INCLUDE) -DMODULE -Wall -O2 TARGET = hello SRC = hello.c all: $(TARGET).o clean: rm -f *.o *~ core ******************************************************************** 錯誤訊息: gcc -D__KERNEL__ -I/usr/src/kernels/2.6.18-1.2798.fc6-i686/hello -DMODULE -Wall -O2 -c -o hello.o hello.c hello.c:4:26: 錯誤:linux/module.h:沒有此一檔案或目錄 hello.c: 在函式 「init_module」 中: hello.c:19: 警告:隱含宣告函式 「printk」 hello.c:19: 錯誤:「KERN_DEBUG」 未宣告 (在此函式內第一次使用) hello.c:19: 錯誤:(即使在一個函式內多次出現,每個未宣告的識別碼在其 hello.c:19: 錯誤:所在的函式內只報告一次。) hello.c:19: 錯誤:expected 「)」 before string constant hello.c: 在函式 「cleanup_module」 中: hello.c:25: 錯誤:「KERN_DEBUG」 未宣告 (在此函式內第一次使用) hello.c:25: 錯誤:expected 「)」 before string constant make: *** [hello.o] Error 1 ************************************************************************** 看上面的錯誤訊息,好像是沒找到module.h,我的module.h所在的路徑為 /usr/src/kernels/2.6.18-1.2798.fc6-i686/include/linux/module.h 但我修改了程式好幾次,仍然出現找不到的錯誤訊息,請問我該如改呢? 謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.115.2
CriLit:試試看先拿掉KERN_DEBUG 05/30 14:15