简体   繁体   English

编译内核模块源代码时如何包含标准头文件?

[英]how to include standard header files when compiling a kernel module source?

I've downloaded, compiled and installed the latest kernel in my machine. 我已经在计算机上下载,编译并安装了最新的内核。 Now, I'm trying to write a kernel module. 现在,我正在尝试编写一个内核模块。 When I try compiling it, I get errors of following similar sort - fatal error: sys/syscall.h: No such file or directory fatal error: linux/module.h: No such file or directory I've tried rewriting the makefile for this in the fashion of including the necessary directories from the source of my latest kernel, but still the problem is persistent. 当我尝试编译它时,出现以下类似的错误-致命错误:sys / syscall.h:没有这样的文件或目录致命错误:linux / module.h:没有这样的文件或目录我尝试重写makefile用于这种方式包括从最新内核的源代码中包含必要的目录,但是问题仍然存在。

Require your suggestions. 需要您的建议。

You can't use libc headers in the kernel. 您不能在内核中使用libc标头。

Moreover, you seem to include syscall.h. 此外,您似乎包括syscall.h。 Syscalls are by nature userspace call. Syscall本质上是用户空间调用。 There is no need for syscalls inside the kernel. 内核内部不需要系统调用。

The include for linux/module.h should work though. linux / module.h的include应该可以工作。 Could you give us the Makefile you are using ? 您能给我们您正在使用的Makefile吗?

Your Makefile should look something like this. 您的Makefile应该看起来像这样。

hello.ko: hello.c
  make ARCH=um -C "/home/abhijit/play/kernel/linux-2.6" M=`pwd` modules

obj-m:= hello.o
objs:= hello.o

and you should have a module_init and module_exit defined in your source file. 并且您应该在源文件中定义一个module_initmodule_exit Do you have these things? 你有这些东西吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM