Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-13-2010, 02:48 AM   #1
LQ Newbie
Registered: Mar 2009
Posts: 28

Rep: Reputation: 15
Installing Kernel Header Files

Hi all
I am using Ubuntu 9.04 with kernel version 2.6.28-11-generic.I want to compile the foll. file but i get <linux/slab.h> no such file or directory.


int main()
void * ptr;
return 0;

The kernel headers are installed in my system at /usr/src/linux-headers-2.6.28-11-generic/ directory. During compilation i specified as follows:

gcc -I/usr/src/linux-headers-2.6.28-11-generic/include mem_alloc.c

So can you tell me what might be the problem why gcc is unable to find the linux/slab.h header file?

Thanks & Regards
Old 02-13-2010, 07:55 PM   #2
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
If the file /usr/src/linux-headers-2.6.28-11-generic/include/linux/slab.h or /usr/include/linux/slab.h exist, the error can be a bug in gcc/cpp, which is unprobable. Thus please check if one of the above files really exists and is readable.

I do not understand the meaning of your program. kmalloc() is a kernel function that is not available in userspace (it allocates kernel memory). An equivalent replacement is the function malloc() from malloc.h

If you want to write a kernel module, then using a main() function is the wrong way to start with. In this case you should use:

 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/slab.h>

  static int __init mymod_init(void)
        void * ptr = kmalloc(1024,GPF_KERNEL);
        printk(KERN_INFO "kernel memory at %p\n", ptr);
        return 0;


Last edited by irmin; 02-13-2010 at 08:04 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
why are opensuse 11 kernel header files not the same as kernel and source from yast backthefup SUSE / openSUSE 1 07-14-2008 09:31 AM
Kernel Header files needed for lilo (config.h no longer in kernel!) gvp87 Linux - Software 1 04-29-2008 03:32 PM
Installing Kernel Header files ? hemanth83_in Linux - Newbie 26 04-10-2008 10:13 AM
Installing kernel header files for old kernel skibud2 Linux From Scratch 2 01-14-2008 12:31 AM
installing a VPN client - needs kernel header files mehlkelm Linux - Software 1 06-11-2003 04:01 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:59 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration