LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 02-13-2010, 01:48 AM   #1
ananth86coolguy
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.

mem_alloc.c

#include<linux/slab.h>
int main()
{
void * ptr;
ptr=kmalloc(1024,GPF_KERNEL);
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
Ananth
 
Old 02-13-2010, 06:55 PM   #2
irmin
Member
 
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:

Code:
 #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);
        kfree(ptr);
        return 0;
   }

   module_init(mymod_init);

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


Reply


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 08:31 AM
Kernel Header files needed for lilo (config.h no longer in kernel!) gvp87 Linux - Software 1 04-29-2008 02:32 PM
Installing Kernel Header files ? hemanth83_in Linux - Newbie 26 04-10-2008 09:13 AM
Installing kernel header files for old kernel skibud2 Linux From Scratch 2 01-13-2008 11:31 PM
installing a VPN client - needs kernel header files mehlkelm Linux - Software 1 06-11-2003 03:01 AM


All times are GMT -5. The time now is 08:09 AM.

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