Wrangler
Wrangler

Reputation: 71

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.

Require your suggestions.

Upvotes: 3

Views: 2906

Answers (2)

mripard
mripard

Reputation: 2366

You can't use libc headers in the kernel.

Moreover, you seem to include syscall.h. Syscalls are by nature userspace call. There is no need for syscalls inside the kernel.

The include for linux/module.h should work though. Could you give us the Makefile you are using ?

Upvotes: 1

hoskeri
hoskeri

Reputation: 347

Your Makefile should look something like this.

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. Do you have these things?

Upvotes: 0

Related Questions