当前位置: 技术问答>linux和unix
内核模块hello.c编译通不过……
来源: 互联网 发布时间:2016-09-04
本文导语: #include #if defined(CONFIG_SMP) #define __SMP__ #endif #if defined(CONFIG_MODVERSIONS) #define MODVERSIONS #include #endif #include static __init int init_modules(void) { printk(KERN_DEBUG "Hello, kernel!n"); return 0; } static __exit void cleanup_modules(void) { pri...
#include
#if defined(CONFIG_SMP)
#define __SMP__
#endif
#if defined(CONFIG_MODVERSIONS)
#define MODVERSIONS
#include
#endif
#include
static __init int init_modules(void) {
printk(KERN_DEBUG "Hello, kernel!n");
return 0;
}
static __exit void cleanup_modules(void) {
printk(KERN_DEBUG "Good-bye, kernel!n");
}
操作系统:debian 5.04/gcc-4.3
命令:gcc -D__KERNEL__ -I/usr/src/linnux-headers-$(uname -r)/include -DMODULE -Wall -O2 -c kernel.c -o kernel.o
错误提示:
double@DES:~$ gcc -D__KERNEL__ -I/usr/src/linux-headers-$(uname -r)/include -DMODULE -Wall -O2 -c kernel.c -o kernel.o
In file included from /usr/src/linux-headers-2.6.26-2-686/include/linux/cache.h:4,
from /usr/src/linux-headers-2.6.26-2-686/include/asm/pda.h:7,
from /usr/src/linux-headers-2.6.26-2-686/include/asm/current_64.h:7,
from /usr/src/linux-headers-2.6.26-2-686/include/asm/current.h:4,
from /usr/src/linux-headers-2.6.26-2-686/include/asm/processor.h:15,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/prefetch.h:14,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/list.h:6,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/module.h:9,
from kernel.c:1:
/usr/src/linux-headers-2.6.26-2-686/include/linux/kernel.h: In function ‘printk_needs_cpu’:
/usr/src/linux-headers-2.6.26-2-686/include/linux/kernel.h:220: error: parameter name omitted
In file included from /usr/src/linux-headers-2.6.26-2-686/include/linux/prefetch.h:14,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/list.h:6,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/module.h:9,
from kernel.c:1:
/usr/src/linux-headers-2.6.26-2-686/include/asm/processor.h: At top level:
/usr/src/linux-headers-2.6.26-2-686/include/asm/processor.h:112: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)
/usr/src/linux-headers-2.6.26-2-686/include/asm/processor.h:112: error: requested alignment is not a constant
In file included from /usr/src/linux-headers-2.6.26-2-686/include/linux/prefetch.h:14,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/list.h:6,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/module.h:9,
from kernel.c:1:
/usr/src/linux-headers-2.6.26-2-686/include/asm/processor.h:155:1: warning: "cache_line_size" redefined
In file included from /usr/src/linux-headers-2.6.26-2-686/include/asm/pda.h:7,
from /usr/src/linux-headers-2.6.26-2-686/include/asm/current_64.h:7,
from /usr/src/linux-headers-2.6.26-2-686/include/asm/current.h:4,
from /usr/src/linux-headers-2.6.26-2-686/include/asm/processor.h:15,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/prefetch.h:14,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/list.h:6,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/module.h:9,
from kernel.c:1:
/usr/src/linux-headers-2.6.26-2-686/include/linux/cache.h:64:1: warning: this is the location of the previous definition
/usr/src/linux-headers-2.6.26-2-686/include/asm/processor.h: In function ‘load_cr3’:
/usr/src/linux-headers-2.6.26-2-686/include/asm/processor.h:187: error: ‘CONFIG_PAGE_OFFSETUL’ undeclared (first use in this function)
/usr/src/linux-headers-2.6.26-2-686/include/asm/processor.h:187: error: (Each undeclared identifier is reported only once
/usr/src/linux-headers-2.6.26-2-686/include/asm/processor.h:187: error: for each function it appears in.)
/usr/src/linux-headers-2.6.26-2-686/include/asm/processor.h: At top level:
/usr/src/linux-headers-2.6.26-2-686/include/asm/processor.h:236: error: requested alignment is not a constant
In file included from /usr/src/linux-headers-2.6.26-2-686/include/asm/thread_info.h:5,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/thread_info.h:47,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/preempt.h:9,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/spinlock.h:49,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/seqlock.h:29,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/time.h:8,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/stat.h:60,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/module.h:10,
from kernel.c:1:
/usr/src/linux-headers-2.6.26-2-686/include/asm/thread_info_64.h: In function ‘current_thread_info’:
/usr/src/linux-headers-2.6.26-2-686/include/asm/thread_info_64.h:66: error: ‘THREAD_SIZE’ undeclared (first use in this function)
/usr/src/linux-headers-2.6.26-2-686/include/asm/thread_info_64.h: In function ‘stack_thread_info’:
/usr/src/linux-headers-2.6.26-2-686/include/asm/thread_info_64.h:74: error: ‘THREAD_SIZE’ undeclared (first use in this function)
In file included from /usr/src/linux-headers-2.6.26-2-686/include/linux/elf.h:7,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/module.h:14,
from kernel.c:1:
/usr/src/linux-headers-2.6.26-2-686/include/asm/elf.h: In function ‘elf_common_init’:
/usr/src/linux-headers-2.6.26-2-686/include/asm/elf.h:166: error: ‘struct pt_regs’ has no member named ‘r8’
/usr/src/linux-headers-2.6.26-2-686/include/asm/elf.h:166: error: ‘struct pt_regs’ has no member named ‘r9’
/usr/src/linux-headers-2.6.26-2-686/include/asm/elf.h:166: error: ‘struct pt_regs’ has no member named ‘r10’
/usr/src/linux-headers-2.6.26-2-686/include/asm/elf.h:166: error: ‘struct pt_regs’ has no member named ‘r11’
/usr/src/linux-headers-2.6.26-2-686/include/asm/elf.h:167: error: ‘struct pt_regs’ has no member named ‘r12’
/usr/src/linux-headers-2.6.26-2-686/include/asm/elf.h:167: error: ‘struct pt_regs’ has no member named ‘r13’
/usr/src/linux-headers-2.6.26-2-686/include/asm/elf.h:167: error: ‘struct pt_regs’ has no member named ‘r14’
/usr/src/linux-headers-2.6.26-2-686/include/asm/elf.h:167: error: ‘struct pt_regs’ has no member named ‘r15’
In file included from /usr/src/linux-headers-2.6.26-2-686/include/linux/mmzone.h:16,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/gfp.h:4,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/slab.h:12,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/percpu.h:5,
from /usr/src/linux-headers-2.6.26-2-686/include/asm/local.h:4,
from /usr/src/linux-headers-2.6.26-2-686/include/linux/module.h:19,
from kernel.c:1:
/usr/src/linux-headers-2.6.26-2-686/include/linux/nodemask.h: In function ‘__first_node’:
/usr/src/linux-headers-2.6.26-2-686/include/linux/nodemask.h:233: warning: implicit declaration of function ‘find_first_bit’
/usr/src/linux-headers-2.6.26-2-686/include/linux/nodemask.h: In function ‘__next_node’:
/usr/src/linux-headers-2.6.26-2-686/include/linux/nodemask.h:239: warning: implicit declaration of function ‘find_next_bit’
/usr/src/linux-headers-2.6.26-2-686/include/linux/nodemask.h: In function ‘__first_unset_node’:
/usr/src/linux-headers-2.6.26-2-686/include/linux/nodemask.h:257: warning: implicit declaration of function ‘find_first_zero_bit’
In file included from /usr/src/linux-headers-2.6.26-2-686/include/linux/module.h:21,
from kernel.c:1:
/usr/src/linux-headers-2.6.26-2-686/include/asm/module.h:70:2: error: #error unknown processor family
|
http://blog.csdn.net/pottichu/archive/2007/11/19/1892245.aspx
你的内核是2.6的, 写个 Makefile.
# Makefile2.6
ifneq ($(KERNELRELEASE),)
#kbuild syntax. dependency relationshsip of files and target modules are listed here.
mymodule-objs := hello.o
obj-m := hello.o
else
PWD := $(shell pwd)
KVER ?= $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
all:
$(MAKE) -C $(KDIR) M=$(PWD)
clean:
rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions
endif
你的内核是2.6的, 写个 Makefile.
# Makefile2.6
ifneq ($(KERNELRELEASE),)
#kbuild syntax. dependency relationshsip of files and target modules are listed here.
mymodule-objs := hello.o
obj-m := hello.o
else
PWD := $(shell pwd)
KVER ?= $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
all:
$(MAKE) -C $(KDIR) M=$(PWD)
clean:
rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions
endif
|
是不是因为没有写许可证GPL
|
看这个网址:http://topic.csdn.net/u/20100205/16/ea8080df-b284-4dd6-9f92-c6bcff33c497.html。2.6版本的linux驱动程序编译和2.4的不一样。