LinuxÒÁµéÔ°ÂÛ̳'s Archiver

linkstack ·¢±íÓÚ 2008-3-17 11:25

±àÒëÄ£¿éʱ³öÏֵĴíÎó

Ä£¿éÔ´Îļþ(hello.c)´úÂë:
#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void){
        printk("<1>hello word!\n");
        return 0;
}

void cleanup_module(void){
       
}

Makefile:
TARGET  := hello
WARN    := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/2.6.22.6-1/build/include/
CFLAGS  := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC      := gcc
        
${TARGET}.o: ${TARGET}.c

.PHONY: clean

makeʱµÄ´íÎóÌáʾ:
gcc -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/2.6.22.6-1/build/include/   -c -o hello.o hello.c
In file included from /lib/modules/2.6.22.6-1/build/include/asm/thread_info.h:16,
                 from /lib/modules/2.6.22.6-1/build/include/linux/thread_info.h:21,
                 from /lib/modules/2.6.22.6-1/build/include/linux/preempt.h:9,
                 from /lib/modules/2.6.22.6-1/build/include/linux/spinlock.h:49,
                 from /lib/modules/2.6.22.6-1/build/include/linux/module.h:9,
                 from hello.c:1:
/lib/modules/2.6.22.6-1/build/include/asm/processor.h:83: error: ¡®CONFIG_X86_L1_CACHE_SHIFT¡¯ undeclared here (not in a function)
/lib/modules/2.6.22.6-1/build/include/asm/processor.h:83: error: requested alignment is not a constant
In file included from /lib/modules/2.6.22.6-1/build/include/linux/module.h:21,
                 from hello.c:1:
/lib/modules/2.6.22.6-1/build/include/asm/module.h:64:2: error: #error unknown processor family

Äܰï°ïÎÒÂð(linuxΪ2.6.22.6-1)

[[i] ±¾Ìû×îºóÓÉ linkstack ÓÚ 2008-3-17 11:27 ±à¼­ [/i]]

zltjiangshi ·¢±íÓÚ 2008-3-18 10:45

ÄãµÄÄ£¿éÊǰ´2.4µÄ¹æÔò£¬ÔÚ2.6ÀïÃæ²»ÊÇÕâôдµÄ
È¥°Ù¶Èһϡ°¿ª·¢¼òµ¥µÄ Linux2.6 ÄÚºËÄ£¿é¡±
Äã»áÓÐÊÕ»ñµÄ¡£

linkstack ·¢±íÓÚ 2008-3-18 19:17

¸Ðл°æÖ÷£¡·Ç³£¸Ðл£¡
¸ÄÕýºóµÄMakefile:
obj-m += hello.o

ÃüÁî:
make -C /usr/src/linux-`uname -r` SUBDIRS=$PWD modules

¾Í¿ÉÒÔÕý³£µØ±àÒëÄ£¿éÁË
ÔٴθÐл°æÖ÷£¡

Ò³: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.