歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> Linux資訊 >> Linux文化

內核模塊編譯出錯,高分求教大家幫忙


簡單一個Hello Wo r l d 的L i n u x內核模塊,可是編譯的時候就是出錯 程序如下: hello.c #include /* We're doing kernel work */ #include /* Specifically, a module */ /* Initialize the module */ int init_module() { printk("Hello, world - this is the kernel speaking\n"); /* If we return a non zero value, it means that init_module failed and * the kernel module can't be loaded */ return 0; } /* Cleanup - undid whatever init_module did */ void cleanup_module() { printk("Short is the life of a kernel module\n"); } Makefile如下: # Makefile for a basic kernel module CC = gcc MODCFLAGS := -O6 -Wall -DCONFIG_KERNELD -DMODULE -D__KERNEL__ -DLinux hello.o : hello.c /usr/include/linux/version.h $(CC) $(MODCFLAGS) -c hello.c

出錯: gcc -O6 -Wall -DCONFIG_KERNELD -DMODULE -D__KERNEL__ -DLinux -c hello.c in file included from /usr/include/linux/module.h:20 from hello.c:2 /usr/include/asm/module.h:56:2: #error unknown processor family make: *** [hello.o] error 1

>>> 此貼的回復 >> 沒有定義cpu類型?

>>> 此貼的回復 >> 看Linux Device Driver 3/e。

>>> 此貼的回復 >> 我的也出錯,也想發表,suse9.1 #include #include #include

static int init_module(void) { printk("Hello,world!\n"); return 0; }

static void cleanup_module(void) { printk("Bay1\n"); }

module_init(init_module); module_exit(cleanup_module);

linux:/software # gcc -c hello.c In file included from /usr/include/linux/sched.h:12, from /usr/include/linux/module.h:9, from hello.c:2: /usr/include/linux/jiffies.h:16: error: parse error before "jiffies_64" /usr/include/linux/jiffies.h:20: error: parse error before "get_jiffies_64" In file included from /usr/include/linux/sched.h:21, from /usr/include/linux/module.h:9, from hello.c:2: /usr/include/asm/mmu.h:13: error: field `sem' has incomplete type In file included from /usr/include/linux/signal.h:4, from /usr/include/linux/sched.h:25, from /usr/include/linux/module.h:9, from hello.c:2: /usr/include/linux/list.h:604:2: warning: #warning "don't include kernel headers in userspace" In file included from /usr/include/asm/siginfo.h:4, from /usr/include/linux/signal.h:7, from /usr/include/linux/sched.h:25, from /usr/include/linux/module.h:9, from hello.c:2: /usr/include/asm-generic/siginfo.h:53: error: size of array `_pad' is too large In file included from /usr/include/linux/sched.h:27, from /usr/include/linux/module.h:9, from hello.c:2: /usr/include/linux/fs_struct.h:9: error: parse error before "rwlock_t" /usr/include/linux/fs_struct.h:13: error: parse error before '}' token In file included from /usr/include/linux/sched.h:29, from /usr/include/linux/module.h:9, from hello.c:2: /usr/include/linux/completion.h:15: error: parse error before "wait_queue_head_t" /usr/include/linux/completion.h: In function `init_completion': /usr/include/linux/completion.h:26: error: dereferencing pointer to incomplete type /usr/include/linux/completion.h:27: error: dereferencing pointer to incomplete type In file included from /usr/include/linux/sched.h:30, from /usr/include/linux/module.h:9, from hello.c:2: /usr/include/linux/pid.h: At top level: /usr/include/linux/pid.h:18: error: field `task_list' has incomplete type /usr/include/linux/pid.h:19: error: field `hash_chain' has incomplete type /usr/include/linux/pid.h:24: error: field `pid_chain' has incomplete type In file included from /usr/include/linux/module.h:9, from hello.c:2: /usr/include/linux/sched.h:93: error: parse error before "process_counts" In file included from /usr/include/linux/sched.h:102, from /usr/include/linux/module.h:9, from hello.c:2: /usr/include/linux/timer.h:10: error: field `entry' has incomplete type hello.c:6: warning: static declaration for `init_module' follows non-static hello.c:12: warning: static declaration for `cleanup_module' follows non-static hello.c:16: error: parse error before "__attribute_used__" hello.c:16: warning: initialization makes integer from pointer without a cast hello.c:16: warning: data definition has no type or storage class hello.c:17: error: parse error before "__attribute_used__" hello.c:17: error: redefinition of `__attribute_used__' hello.c:16: error: `__attribute_used__' previously defined here hello.c:17: warning: initialization makes integer from pointer without a cast hello.c:17: warning: data definition has no type or storage class

>>> 此貼的回復 >> 2.6的版本用kernel building system 的規則編譯。具體方法在ldd3上一清二楚。


Copyright © Linux教程網 All Rights Reserved