Marwah Abdelaal
Marwah Abdelaal

Reputation: 121

Including Linux Headers returns No such file or directory

I'm trying to write a C code that will make use of the memory information in Linux kernel (Virtual address space of a process, status of a process and such info.)

I'll need to include the below headers to get these info.

#include<linux/init.h>
#include<linux/module.h>
#include<linux/mm.h>

The actual files exists under the linux folder, but when compiling the file using gcc it returns that

No such file or directory

Can someone please explain why i'm getting this error! and what should i do?

Upvotes: 0

Views: 5153

Answers (1)

danglingpointer
danglingpointer

Reputation: 4920

The answer to your question.

Install the missing package kernel-devel using apt-get

NOTE: I've mentioned apt install package you can use what is supported on your system for example yum.

If you're not able to install kernel-devel then you can try this which install generic Linux headers.

sudo apt-get update && sudo apt-get install linux-headers-`uname -r`

Then you can check where the init.h or module.h using locate utility

and then add the path in your compilation using -I flag.

gcc -g your_file.c -I/usr/path/of/the/kernel/header/include

Upvotes: 1

Related Questions