在迈克尔·斯帕克斯(Michael Sparks)在伦敦SO DevDay的Peter Norvig的Python拼写检查工作中,我正在重温Python.
他强调的一点是要看看Python的清晰程度.没有用于范围的大括号,而是使用空格来指示块范围.
这让我思考.我想知道这是否是构建make目标所需命令的TAB缩进背后的原因.
这是一样的清晰度吗?要轻松区分目标和构建目标所需的命令?
我写了一个简单的模块:
#define __KERNEL__
#define MODULE
#include <linux/kernel.h>
#include <linux/module.h>
int init_module(void)
{
printk("Hello, world\n");
return 0;
}
void cleanup_module(void)
{
printk("Goodbye\n");
}
Run Code Online (Sandbox Code Playgroud)
并使用此命令编译它:
cc -c hello.c
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误:
linux/module.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)
有什么建议?
编辑:我用过这个commad:
cc -I/usr/src/linux-headers-3.0.0-17-generic/include -c hello.c
Run Code Online (Sandbox Code Playgroud)
它领先一步,现在我收到这个错误:
In file included from /usr/src/linux-headers-3.0.0-17-generic/include/linux/kernel.h:13:0,
from hello.c:3:
/usr/src/linux-headers-3.0.0-17-generic/include/linux/linkage.h:5:25: fatal error: asm/linkage.h: No such file or directory
compilation terminated.
Run Code Online (Sandbox Code Playgroud) 这是一个"Hello.c"模块和"Makefile".make从woking目录执行后,我收到以下消息:
make:没有什么可以为'all'做的.
这是"Hello.c"文件:
#include <linux/module.h> // included for all kernel modules
#include <linux/kernel.h> // included for KERN_INFO
#include <linux/init.h> // included for __init and __exit macros
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Lakshmanan");
MODULE_DESCRIPTION("A Simple Hello World module");
static int __init hello_init(void) {
printk(KERN_INFO "Hello world!\n");
return 0; // Non-zero return means that the module couldn't be
}
static void __exit hello_cleanup(void) {
printk(KERN_INFO "Cleaning up module.\n");
}
module_init(hello_init);
module_exit(hello_cleanup);
Run Code Online (Sandbox Code Playgroud)
和"Makefile":
obj-m += hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean: …Run Code Online (Sandbox Code Playgroud) c ×2
makefile ×2
c++ ×1
compilation ×1
gnu-make ×1
kernel ×1
linux ×1
linux-kernel ×1
syntax ×1