当前位置: 技术问答>linux和unix
简单的模块编译通不过……
来源: 互联网 发布时间:2016-09-01
本文导语: #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...
#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
|
不懂,帮顶,顺便问下,这是内核吗??抱歉,我只是好奇!
|
这种模块编译需要有kbuild支持吧才可以生成对应的模块吧。
我参考一个模块编译Makefile文件生成下面的Makefile, 然后再编译是可以生成模块的。
我的系统是Ubuntu,内核为:2.6.31-20-generic
我参考一个模块编译Makefile文件生成下面的Makefile, 然后再编译是可以生成模块的。
KERNEL_VERSION := `uname -r`
KERNEL_DIR := /lib/modules/$(KERNEL_VERSION)/build
PWD := $(shell pwd)
obj-m := simplemodule.o
all: simplemodule
simplemodule:
@echo "Building simple module driver..."
@(cd $(KERNEL_DIR) && make -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules)
clean:
-rm -f *.o *.ko .*.cmd .*.flags *.mod.c Modules.symvers
-rm -rf .tmp_versions
我的系统是Ubuntu,内核为:2.6.31-20-generic