日期:2014-05-16  浏览次数:20671 次

求助,编译最简单的“init/cleanup驱动程序”出错
我在debian etch上编译一个驱动程序报错,是很简单的一个init/cleanup程序,哪位大哥帮忙看一下吧,先谢谢了。。


源程序(程序应该没有问题,就是《linux程序设计》第三版第十八章的第一个例子程序):

#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");
}


编译时的命令(也是书上写的编译方法):

gcc -D__KERNEL__ -I/usr/src/linux-headers-2.6.18-4-686/include -DMODULE -Wall -O2 -c hello.c -o hello.o


下面是gcc报的错误:

In file included from /usr/src/linux-headers-2.6.18-4-686/include/asm/thread_info.h:16,
  from /usr/src/linux-headers-2.6.18-4-686/include/linux/thread_info.h:21,
  from /usr/src/linux-headers-2.6.18-4-686/include/linux/preempt.h:9,
  from /usr/src/linux-headers-2.6.18-4-686/include/linux/spinlock.h:49,
  from /usr/src/linux-headers-2.6.18-4-686/include/linux/capability.h:45,
  from /usr/src/linux-headers-2.6.18-4-686/include/linux/sched.h:44,
  from /usr/src/linux-headers-2.6.18-4-686/include/linux/module.h:9,
  from hello.c:4:
/usr/src/linux-headers-2.6.18-4-686/include/asm/processor.h:80: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)
/usr/src/linux-headers-2.6.18-4-686/include/asm/processor.h:80: error: requested alignment is not a constant
In file included from /usr/src/linux-headers-2.6.18-4-686/include/linux/rwsem.h:24,
  from /usr/src/linux-headers-2.6.18-4-686/include/asm/semaphore.h:42,
  from /usr/src/linux-headers-2.6.18-4-686/include/linux/sched.h:57,
  from /usr/src/linux-headers-2.6.18-4-686/include/linux/module.h:9,
  from hello.c:4:
/usr/src/linux-headers-2.6.18-4-686/include/asm/rwsem.h: In function ‘__down_read’:
/usr/src/linux-headers-2.6.18-4-686/include/asm/rwsem.h:104: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux-headers-2.6.18-4-686/include/asm/rwsem.h: In function ‘__down_write_nested’:
/usr/src/linux-headers-2.6.18-4-686/include/asm/rwsem.h:156: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux-headers-2.6.18-4-686/include/asm/rwsem.h: In function ‘__up_read’:
/usr/src/linux-headers-2.6.18-4-686/include/asm/rwsem.h:198: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux-headers-2.6.18-4-686/include/asm/rwsem.h:192: warning: unused variable ‘tmp’
/usr/src/linux-headers-2.6.18-4-686/include/asm/rwsem.h: In function ‘__up_write’:
/usr/src/linux-headers-2.6.18-4-686/include/asm/rwsem.h:224: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux-headers-2.6.18-4-686/include/asm/rwsem.h: In function ‘__downgrade_write’:
/usr/src/linux-headers-2.6.18-4-686/include/asm/rwsem.h:249: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
In file included from /usr/src/linux-headers-2.6.18-4-686/include/linux/sched.h:57,
  from /usr/src/linux-headers-2.6.18-4-686/include/linux/module.h:9,
  from hello.c:4:
/usr/src/linux-headers-2.6.18-4-686/include/asm/semaphore.h: In function ‘down’:
/usr/src/linux-headers-2.6.18-4-686/include/asm/semaphore.h:105: error: expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux-headers-2.6.18-4-686/include/asm/semaphore.h: In function ‘down_interruptible’:
/usr/src/linux-headers-2.6.18-4-686/include/asm/semaphore.h:130: error