+ -
当前位置:首页 → 问答吧 → linux内核模块编译问题

linux内核模块编译问题

时间:2011-10-25

来源:互联网

我在网上copy了别人的一个内核helloworld模块,具体代码如下:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */


int init_module(void)
{
  printk("<1>Hello world 1.\n");

  // A non 0 return means init_module failed; module can't be loaded.
  return 0;
}


void cleanup_module(void)
{
  printk(KERN_ALERT "Goodbye world 1.\n");
}  
makefile如下:
TARGET := hello-1
WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
CFLAGS := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC := gcc-3.0

${TARGET}.o: ${TARGET}.c

.PHONY: clean

clean:
  rm -rf {TARGET}.o
编译时总出现如下错误:
/lib/modules/2.6.32-34-generic/build/include/linux/bitops.h:17:24: error: asm/bitops.h: 没有那个文件或目录
类似的有好几条,还有
/lib/modules/2.6.32-34-generic/build/include/linux/thread_info.h:82: error: dereferencing pointer to incomplete type
/lib/modules/2.6.32-34-generic/build/include/linux/module.h:319: error: expected specifier-qualifier-list before ‘Elf_Sym’
/lib/modules/2.6.32-34-generic/build/include/linux/module.h:455: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
In file included from hello.c:1:
/lib/modules/2.6.32-34-generic/build/include/linux/module.h:712: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
求高手指教。

作者: emeis   发布时间: 2011-10-25

引用楼主 emeis 的回复:
我在网上copy了别人的一个内核helloworld模块,具体代码如下:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */


int init_module(void)
{
printk("<1>Hello ……
可能内核版本不兼容。

作者: linwhwylb   发布时间: 2011-10-25

热门下载

更多