关于在Ubuntu的环境下,编译内核模块Hello World!问题!!
-
- 帖子: 7
- 注册时间: 2008-04-26 14:34
关于在Ubuntu的环境下,编译内核模块Hello World!问题!!
#define MODULE
#include <linux/module.h>
int init_module()
{
printk("<1>Hello World!\n0");
return 0;
}
void cleanup_module()
{
printk("<1> Goodbye!\n");
}
fangquan@fangquan-desktop:~/Desktop/modul$ gcc -c helloworld.c
helloworld.c:2:26: 错误: linux/module.h:No such file or directory
fangquan@fangquan-desktop:~/Desktop/modul$
请问这问题怎么解决,谢谢
#include <linux/module.h>
int init_module()
{
printk("<1>Hello World!\n0");
return 0;
}
void cleanup_module()
{
printk("<1> Goodbye!\n");
}
fangquan@fangquan-desktop:~/Desktop/modul$ gcc -c helloworld.c
helloworld.c:2:26: 错误: linux/module.h:No such file or directory
fangquan@fangquan-desktop:~/Desktop/modul$
请问这问题怎么解决,谢谢
-
- 帖子: 17
- 注册时间: 2006-11-02 12:12
-
- 帖子: 7
- 注册时间: 2008-04-26 14:34
我看过了,下面就是按照他的方法来编译的,出现了一下情况:
fangquan@fangquan-desktop:~/driver$ make
make -C /lib/modules/2.6.20.3-ubuntu1/build M=/home/fangquan/driver modules
make[1]: Entering directory `/usr/src/linux-source-2.6.20'
scripts/Makefile.build:17: /home/fangquan/driver/Makefile: No such file or directory
make[2]: *** 没有规则可以创建目标“/home/fangquan/driver/Makefile”。 停止。
make[1]: *** [_module_/home/fangquan/driver] 错误 2
make[1]: Leaving directory `/usr/src/linux-source-2.6.20'
make: *** [modules] 错误 2
fangquan@fangquan-desktop:~/driver$ ls
hello.c hello.c~ makefile makefile~
fangquan@fangquan-desktop:~/driver$
我想问一下,这是什么原因造成的。
fangquan@fangquan-desktop:~/driver$ make
make -C /lib/modules/2.6.20.3-ubuntu1/build M=/home/fangquan/driver modules
make[1]: Entering directory `/usr/src/linux-source-2.6.20'
scripts/Makefile.build:17: /home/fangquan/driver/Makefile: No such file or directory
make[2]: *** 没有规则可以创建目标“/home/fangquan/driver/Makefile”。 停止。
make[1]: *** [_module_/home/fangquan/driver] 错误 2
make[1]: Leaving directory `/usr/src/linux-source-2.6.20'
make: *** [modules] 错误 2
fangquan@fangquan-desktop:~/driver$ ls
hello.c hello.c~ makefile makefile~
fangquan@fangquan-desktop:~/driver$
我想问一下,这是什么原因造成的。
-
- 帖子: 7
- 注册时间: 2008-04-26 14:34
在lib下有以下文件
fangquan@fangquan-desktop:/lib/modules$ ls
2.6.20-15-generic 2.6.20-16-generic 2.6.20.3-ubuntu1
fangquan@fangquan-desktop:/lib/modules$ cd 2.6.20.3-ubuntu1
fangquan@fangquan-desktop:/lib/modules/2.6.20.3-ubuntu1$ ls
build modules.dep modules.ofmap modules.usbmap
kernel modules.ieee1394map modules.pcimap source
modules.alias modules.inputmap modules.seriomap
modules.ccwmap modules.isapnpmap modules.symbols
fangquan@fangquan-desktop:/lib/modules/2.6.20.3-ubuntu1$
fangquan@fangquan-desktop:/lib/modules$ ls
2.6.20-15-generic 2.6.20-16-generic 2.6.20.3-ubuntu1
fangquan@fangquan-desktop:/lib/modules$ cd 2.6.20.3-ubuntu1
fangquan@fangquan-desktop:/lib/modules/2.6.20.3-ubuntu1$ ls
build modules.dep modules.ofmap modules.usbmap
kernel modules.ieee1394map modules.pcimap source
modules.alias modules.inputmap modules.seriomap
modules.ccwmap modules.isapnpmap modules.symbols
fangquan@fangquan-desktop:/lib/modules/2.6.20.3-ubuntu1$
-
- 帖子: 7
- 注册时间: 2008-04-26 14:34
在lib下有以下文件
fangquan@fangquan-desktop:/lib/modules$ ls
2.6.20-15-generic 2.6.20-16-generic 2.6.20.3-ubuntu1
fangquan@fangquan-desktop:/lib/modules$ cd 2.6.20.3-ubuntu1
fangquan@fangquan-desktop:/lib/modules/2.6.20.3-ubuntu1$ ls
build modules.dep modules.ofmap modules.usbmap
kernel modules.ieee1394map modules.pcimap source
modules.alias modules.inputmap modules.seriomap
modules.ccwmap modules.isapnpmap modules.symbols
fangquan@fangquan-desktop:/lib/modules/2.6.20.3-ubuntu1$
不知道是否因缺乏安装包造成的
fangquan@fangquan-desktop:/lib/modules$ ls
2.6.20-15-generic 2.6.20-16-generic 2.6.20.3-ubuntu1
fangquan@fangquan-desktop:/lib/modules$ cd 2.6.20.3-ubuntu1
fangquan@fangquan-desktop:/lib/modules/2.6.20.3-ubuntu1$ ls
build modules.dep modules.ofmap modules.usbmap
kernel modules.ieee1394map modules.pcimap source
modules.alias modules.inputmap modules.seriomap
modules.ccwmap modules.isapnpmap modules.symbols
fangquan@fangquan-desktop:/lib/modules/2.6.20.3-ubuntu1$
不知道是否因缺乏安装包造成的
-
- 帖子: 7
- 注册时间: 2008-04-26 14:34
-
- 帖子: 4
- 注册时间: 2008-07-01 15:30
我也遇到這個問題,可能是因為2.4和2.6的kernel module編譯方式不一樣
你可以試試看
//hello.c
#include<linux/init.h>
#include<linux/module.h>
#include<linux/moduleparam.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "hello,world\n");
return 0;
}
static int hello_exit(void)
{
printk(KERN_ALERT "goodbye,world\n");
return 0;
}
module_init(hello_init);
module_exit(hello_exit);
//Makefile
ifeq ($(KERNELRELEASE),)
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD :=$(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
.PHONY:modules modules_install clean
else
obj-m:=hello.o
endif
你可以試試看
//hello.c
#include<linux/init.h>
#include<linux/module.h>
#include<linux/moduleparam.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "hello,world\n");
return 0;
}
static int hello_exit(void)
{
printk(KERN_ALERT "goodbye,world\n");
return 0;
}
module_init(hello_init);
module_exit(hello_exit);
//Makefile
ifeq ($(KERNELRELEASE),)
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD :=$(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
.PHONY:modules modules_install clean
else
obj-m:=hello.o
endif
-
- 帖子: 4
- 注册时间: 2008-07-01 15:30
-
- 帖子: 4
- 注册时间: 2008-07-01 15:30
-
- 帖子: 4
- 注册时间: 2008-07-01 15:30
你只要加上Makefile就可以
obj-m:=hello.o
把hello.o改成你的helloworld.o
如後不會顯示出來
請在你可以cat /var/log/syslog |grep hello
查看日志,如果有hello,world就说明成功了。
viewtopic.php?t=126764
obj-m:=hello.o
把hello.o改成你的helloworld.o
如後不會顯示出來
請在你可以cat /var/log/syslog |grep hello
查看日志,如果有hello,world就说明成功了。
viewtopic.php?t=126764
-
- 帖子: 92
- 注册时间: 2008-04-01 0:10
Re: 关于在Ubuntu的环境下,编译内核模块Hello World!问题!!
gcc -o helloworld.c 吧
-
- 帖子: 1
- 注册时间: 2011-08-10 14:00
Re: 关于在Ubuntu的环境下,编译内核模块Hello World!问题!!
我写的源文件hello.c
#include"include/linux/module.h"
#include"include/linux/configfs.h"
#include"linux/init.h"
#include"include/linux/kernel.h"
static int hello_init(void)
{
printk(KERN_ALERT "Hello.world\n ");
return 0;
}
static int hello_exit(void)
{
pritk(KERN_ALERT "Goodbye.crrunt world\n");
return 0;
}
module_init(hello_init);
module_exit(hello_exit);
写的Makefile是:
obj -m +=hello.o
编译用的命令是:make -C '/usr/src/linux-headers-2.6.31-14-generic/' M=$PWD modules
多出来了这么几个文件:
Module.markers modules modules.order Module.symver
编译提示是:
make: Entering directory `/usr/src/linux-headers-2.6.31-14-generic'
Building modules, stage 2.
MODPOST 0 modules
make: Leaving directory `/usr/src/linux-headers-2.6.31-14-generic'
就是没有hello.ko
我是个新手,请问各位前辈,这该怎么解决???
#include"include/linux/module.h"
#include"include/linux/configfs.h"
#include"linux/init.h"
#include"include/linux/kernel.h"
static int hello_init(void)
{
printk(KERN_ALERT "Hello.world\n ");
return 0;
}
static int hello_exit(void)
{
pritk(KERN_ALERT "Goodbye.crrunt world\n");
return 0;
}
module_init(hello_init);
module_exit(hello_exit);
写的Makefile是:
obj -m +=hello.o
编译用的命令是:make -C '/usr/src/linux-headers-2.6.31-14-generic/' M=$PWD modules
多出来了这么几个文件:
Module.markers modules modules.order Module.symver
编译提示是:
make: Entering directory `/usr/src/linux-headers-2.6.31-14-generic'
Building modules, stage 2.
MODPOST 0 modules
make: Leaving directory `/usr/src/linux-headers-2.6.31-14-generic'
就是没有hello.ko
我是个新手,请问各位前辈,这该怎么解决???