linux/kernel.h : No such file or directory
Solution 1
Do you have /usr/src/linux symbolic link to your /usr/src/linux-headers-2.6.35-28-generic ? If not then create one using following commands
# cd /usr/src
# ln -sfn linux-headers-2.6.35-28-generic linux
Solution 2
You can't just use a traditional-style Makefile
with Linux kernel modules; while you might be able to force something to work, it'll be a painful experience.
Start by reading the Documentation/kbuild/modules.txt
file; it'll describe exactly what you need to do when writing a module Makefile
so that it can hook neatly into the kernel's Kbuild
environment. Your Makefile
will probably look something like this:
ifneq ($(KERNELRELEASE),)
# kbuild part of makefile
obj-m := 8123.o
8123-y := 8123_if.o 8123_pci.o 8123_bin.o
else
# normal makefile
KDIR ?= /lib/modules/`uname -r`/build
default:
$(MAKE) -C $(KDIR) M=$$PWD
# Module specific targets
genbin:
echo "X" > 8123_bin.o_shipped
endif
Please trust me on this; while you might think you're "just one small change" from getting your own Makefile
to work, even minor changes in kernel version will completely destroy your build all over again. Just take the hour now to write a Kbuild
-compatible Makefile
for your module. I wasted weeks of my life trying to maintain a pre-existing Makefile
when the Kbuild
infrastructure was introduced. Every new kernel caused me to lose hours of productivity.
Solution 3
For me this file ("linux/kernel.h") is in the package linux-libc-dev (Kubuntu 10.10).
Solution 4
just as what @sarnold said , you should use the different Makefile.Just as following:
obj-m += hello.o
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
and use the command:
insmod hello.ko
to install this module.
Admin
Updated on February 10, 2020Comments
-
Admin about 4 years
I am going to write a Hello World module in Ubuntu 10.10 (with the kernel 2.6.35-28-generic). Headers are located:
/usr/src/linux-headers-2.6.35-28-generic
hello.c:
#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"); }
and Makefile:
CC = gcc CFLAGS = -Wall -DMODULE -D__KERNEL__ hello.o: hello.c $(CC) $(CFLAGS) -c hello.c echo insmod hello.o to install echo rmmod to delete
There is an error while make:
hello.c:1: fatal error: linux/kernel.h : No such file or directory compilation terminated.
How do I solve this?
-
Admin about 13 yearsI have created: ivan@ivan-MS-N031:/usr/src$ ls -l total 73080 lrwxrwxrwx 1 root src 31 2011-04-10 14:57 linux -> linux-headers-2.6.35-28-generic but error still appeared...
-
Admin about 13 yearsOoops... There was an spaces in < linux/kernel.h >
-
Tebe over 12 yearslibc is library for c programming language. how can this touch linux/module.h ?
-
Zitrax over 12 years@shbk I was referring to the error message about "linux/kernel.h" not module.h. Here you can see the content of the package: packages.debian.org/squeeze/i386/linux-libc-dev/filelist
-
Tebe over 12 yearsi didn't do space, i 've done all what is written here, but error appears still: hello.c:1: fatal error: linux/kernel.h : No such file or directory compilation terminated.