2012-04-20 152 views
5

我试图编译Linux内核: http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html编译Linux内核 - 世界你好

我有一个简单的Hello World程序HELLO-1.cpp

#include <linux/module.h> 
#include <linux/kernel.h> 

int init_module(void) 
{ 
    return 0; 
} 

void cleanup_module(void) 
{ 
} 

但我试图建立它使用Makefile:

obj-m += hello-1.o 

all: 
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules 

clean: 
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean 

我得到了一些错误。

make -C /home/pacman/linux-2.6.34.11/2.6.35.6-45.fc14.i686/build M=/home/pacman/p1 modules 
make: *** /home/pacman/linux-2.6.34.11/2.6.35.6-45.fc14.i686/build: No such file or directory. Stop. 

化妆:* [全部]错误2

我忘记了界定什么?

+0

在我的情况正确编制的例子。在你的情况下,作为参数传递的构建目录没有找到。尝试按照这个[网站](http://www.cyberciti.biz/tips/compiling-linux-kernel-module.html)中的教程来查看它是否解决了您的问题,或者您可以搜索构建你的内核版本的目录并将其作为make的参数传递。 – bacchus 2012-04-20 21:54:38

+0

当我列出 – user289925 2012-04-20 22:25:54

+0

的内容在/home/pacman/linux-2.6.34.11目录中,我希望看到一个构建目录或文件?我有一个Kbuild文件。 – user289925 2012-04-20 22:30:56

回答

1

重命名hello-1。 cpp to hello-1。 Ç(模块必须用C被写),并添加行:

module_init(init_module); 
module_exit(cleanup_module);