linux/init.h: No such file or directory











up vote
3
down vote

favorite












I'm trying to build a kernel module for my class, and I'm getting a massive wall of errors, but at the top of said wall is the infamous 'No such file or directory' error. It seems to be the root of the problem. This not only seems to affect init.h, but also module.h and kernel.h. The first three lines of the program go as follows:



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


I've looked around and tried other paths for where these files ought to be when browsing similar issues, but nothing has worked thus far. The strangest part is that I used this module already; I was provided starter code that had this at the top (I didn't change anything) and it didn't give me that error. Although, obviously the code after is different, but this seems to be the biggest problem at the moment.



The full code is as follows:



#include </usr/include/linux/init.h>
#include </usr/include/linux/module.h>
#include </usr/include/linux/kernel.h>

/* This function is called when the module is loaded. */
int simple_init(void)
{
printk(KERN_INFO "Loading Modulen");
static LIST_HEAD(birthday_list)
struct birthday{
int day;
int month;
int year;
struct list_head list;
};
struct birthday *ptr, *next;
struct birthday *bob;
struct birthday *judy;
struct birthday *josh;
struct birthday *lana;
struct birthday *jan;

bob = kmalloc(sizeof(*bob), GFP_KERNEL);
bob -> day = 17;
bob -> month = 1;
bob -> year = 1990;
INIT_LIST_HEAD(&bob -> list);

...

list_add_tail(bob -> list, &birthday_list);
list_add_tail(judy -> list, &birthday_list);
list_add_tail(josh -> list, &birthday_list);
list_add_tail(lana -> list, &birthday_list);
list_add_tail(jan -> list, &birthday_list);

struct birthday *ptr;

list_for_each_entry(ptr, &birthday_list, list){

kprintf('%d/%d/%d n', ptr -> month, ptr -> day, ptr -> year);
}

list_for_each_entry_safe(ptr, &birthday_list, list){

list_del(&ptr->list);
kfree(ptr);
}

return 0;
}

/* This function is called when the module is removed. */
void simple_exit(void) {
printk(KERN_INFO "Removing Modulen");
}

/* Macros for registering module entry and exit points. */
module_init( simple_init );
module_exit( simple_exit );

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Simple Module");
MODULE_AUTHOR("SGG");









share|improve this question
























  • Where is your copy of init.h, and what is the include path your passing to gcc?
    – user590028
    Feb 10 '15 at 3:23










  • Can you post your code ? Are you using Makefile provided in /lib/module ?
    – Parham Alvani
    Feb 10 '15 at 4:11










  • Well, I have a few things to report. For one, init.h and module.h seem to have vanished. Further, I tried to fix this issue, and things.. somehow went wrong. I tried using the command "sudo apt-get install linux-headers-generic," and it gave me an error message: "E: Package 'linux-headers-generic' has no installation candidate."
    – Robert Crawford
    Feb 10 '15 at 4:20










  • I am not using the Makefile that you're talking about, but there is one in the directory of the module I'm trying to run. As for posting the code, there is a LOT of filler stuff in between that isn't really important... I'll work on getting it posted; I have it running on a virtual machine.
    – Robert Crawford
    Feb 10 '15 at 4:59















up vote
3
down vote

favorite












I'm trying to build a kernel module for my class, and I'm getting a massive wall of errors, but at the top of said wall is the infamous 'No such file or directory' error. It seems to be the root of the problem. This not only seems to affect init.h, but also module.h and kernel.h. The first three lines of the program go as follows:



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


I've looked around and tried other paths for where these files ought to be when browsing similar issues, but nothing has worked thus far. The strangest part is that I used this module already; I was provided starter code that had this at the top (I didn't change anything) and it didn't give me that error. Although, obviously the code after is different, but this seems to be the biggest problem at the moment.



The full code is as follows:



#include </usr/include/linux/init.h>
#include </usr/include/linux/module.h>
#include </usr/include/linux/kernel.h>

/* This function is called when the module is loaded. */
int simple_init(void)
{
printk(KERN_INFO "Loading Modulen");
static LIST_HEAD(birthday_list)
struct birthday{
int day;
int month;
int year;
struct list_head list;
};
struct birthday *ptr, *next;
struct birthday *bob;
struct birthday *judy;
struct birthday *josh;
struct birthday *lana;
struct birthday *jan;

bob = kmalloc(sizeof(*bob), GFP_KERNEL);
bob -> day = 17;
bob -> month = 1;
bob -> year = 1990;
INIT_LIST_HEAD(&bob -> list);

...

list_add_tail(bob -> list, &birthday_list);
list_add_tail(judy -> list, &birthday_list);
list_add_tail(josh -> list, &birthday_list);
list_add_tail(lana -> list, &birthday_list);
list_add_tail(jan -> list, &birthday_list);

struct birthday *ptr;

list_for_each_entry(ptr, &birthday_list, list){

kprintf('%d/%d/%d n', ptr -> month, ptr -> day, ptr -> year);
}

list_for_each_entry_safe(ptr, &birthday_list, list){

list_del(&ptr->list);
kfree(ptr);
}

return 0;
}

/* This function is called when the module is removed. */
void simple_exit(void) {
printk(KERN_INFO "Removing Modulen");
}

/* Macros for registering module entry and exit points. */
module_init( simple_init );
module_exit( simple_exit );

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Simple Module");
MODULE_AUTHOR("SGG");









share|improve this question
























  • Where is your copy of init.h, and what is the include path your passing to gcc?
    – user590028
    Feb 10 '15 at 3:23










  • Can you post your code ? Are you using Makefile provided in /lib/module ?
    – Parham Alvani
    Feb 10 '15 at 4:11










  • Well, I have a few things to report. For one, init.h and module.h seem to have vanished. Further, I tried to fix this issue, and things.. somehow went wrong. I tried using the command "sudo apt-get install linux-headers-generic," and it gave me an error message: "E: Package 'linux-headers-generic' has no installation candidate."
    – Robert Crawford
    Feb 10 '15 at 4:20










  • I am not using the Makefile that you're talking about, but there is one in the directory of the module I'm trying to run. As for posting the code, there is a LOT of filler stuff in between that isn't really important... I'll work on getting it posted; I have it running on a virtual machine.
    – Robert Crawford
    Feb 10 '15 at 4:59













up vote
3
down vote

favorite









up vote
3
down vote

favorite











I'm trying to build a kernel module for my class, and I'm getting a massive wall of errors, but at the top of said wall is the infamous 'No such file or directory' error. It seems to be the root of the problem. This not only seems to affect init.h, but also module.h and kernel.h. The first three lines of the program go as follows:



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


I've looked around and tried other paths for where these files ought to be when browsing similar issues, but nothing has worked thus far. The strangest part is that I used this module already; I was provided starter code that had this at the top (I didn't change anything) and it didn't give me that error. Although, obviously the code after is different, but this seems to be the biggest problem at the moment.



The full code is as follows:



#include </usr/include/linux/init.h>
#include </usr/include/linux/module.h>
#include </usr/include/linux/kernel.h>

/* This function is called when the module is loaded. */
int simple_init(void)
{
printk(KERN_INFO "Loading Modulen");
static LIST_HEAD(birthday_list)
struct birthday{
int day;
int month;
int year;
struct list_head list;
};
struct birthday *ptr, *next;
struct birthday *bob;
struct birthday *judy;
struct birthday *josh;
struct birthday *lana;
struct birthday *jan;

bob = kmalloc(sizeof(*bob), GFP_KERNEL);
bob -> day = 17;
bob -> month = 1;
bob -> year = 1990;
INIT_LIST_HEAD(&bob -> list);

...

list_add_tail(bob -> list, &birthday_list);
list_add_tail(judy -> list, &birthday_list);
list_add_tail(josh -> list, &birthday_list);
list_add_tail(lana -> list, &birthday_list);
list_add_tail(jan -> list, &birthday_list);

struct birthday *ptr;

list_for_each_entry(ptr, &birthday_list, list){

kprintf('%d/%d/%d n', ptr -> month, ptr -> day, ptr -> year);
}

list_for_each_entry_safe(ptr, &birthday_list, list){

list_del(&ptr->list);
kfree(ptr);
}

return 0;
}

/* This function is called when the module is removed. */
void simple_exit(void) {
printk(KERN_INFO "Removing Modulen");
}

/* Macros for registering module entry and exit points. */
module_init( simple_init );
module_exit( simple_exit );

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Simple Module");
MODULE_AUTHOR("SGG");









share|improve this question















I'm trying to build a kernel module for my class, and I'm getting a massive wall of errors, but at the top of said wall is the infamous 'No such file or directory' error. It seems to be the root of the problem. This not only seems to affect init.h, but also module.h and kernel.h. The first three lines of the program go as follows:



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


I've looked around and tried other paths for where these files ought to be when browsing similar issues, but nothing has worked thus far. The strangest part is that I used this module already; I was provided starter code that had this at the top (I didn't change anything) and it didn't give me that error. Although, obviously the code after is different, but this seems to be the biggest problem at the moment.



The full code is as follows:



#include </usr/include/linux/init.h>
#include </usr/include/linux/module.h>
#include </usr/include/linux/kernel.h>

/* This function is called when the module is loaded. */
int simple_init(void)
{
printk(KERN_INFO "Loading Modulen");
static LIST_HEAD(birthday_list)
struct birthday{
int day;
int month;
int year;
struct list_head list;
};
struct birthday *ptr, *next;
struct birthday *bob;
struct birthday *judy;
struct birthday *josh;
struct birthday *lana;
struct birthday *jan;

bob = kmalloc(sizeof(*bob), GFP_KERNEL);
bob -> day = 17;
bob -> month = 1;
bob -> year = 1990;
INIT_LIST_HEAD(&bob -> list);

...

list_add_tail(bob -> list, &birthday_list);
list_add_tail(judy -> list, &birthday_list);
list_add_tail(josh -> list, &birthday_list);
list_add_tail(lana -> list, &birthday_list);
list_add_tail(jan -> list, &birthday_list);

struct birthday *ptr;

list_for_each_entry(ptr, &birthday_list, list){

kprintf('%d/%d/%d n', ptr -> month, ptr -> day, ptr -> year);
}

list_for_each_entry_safe(ptr, &birthday_list, list){

list_del(&ptr->list);
kfree(ptr);
}

return 0;
}

/* This function is called when the module is removed. */
void simple_exit(void) {
printk(KERN_INFO "Removing Modulen");
}

/* Macros for registering module entry and exit points. */
module_init( simple_init );
module_exit( simple_exit );

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Simple Module");
MODULE_AUTHOR("SGG");






c linux module kernel debian






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Community

11




11










asked Feb 10 '15 at 3:15









Robert Crawford

40116




40116












  • Where is your copy of init.h, and what is the include path your passing to gcc?
    – user590028
    Feb 10 '15 at 3:23










  • Can you post your code ? Are you using Makefile provided in /lib/module ?
    – Parham Alvani
    Feb 10 '15 at 4:11










  • Well, I have a few things to report. For one, init.h and module.h seem to have vanished. Further, I tried to fix this issue, and things.. somehow went wrong. I tried using the command "sudo apt-get install linux-headers-generic," and it gave me an error message: "E: Package 'linux-headers-generic' has no installation candidate."
    – Robert Crawford
    Feb 10 '15 at 4:20










  • I am not using the Makefile that you're talking about, but there is one in the directory of the module I'm trying to run. As for posting the code, there is a LOT of filler stuff in between that isn't really important... I'll work on getting it posted; I have it running on a virtual machine.
    – Robert Crawford
    Feb 10 '15 at 4:59


















  • Where is your copy of init.h, and what is the include path your passing to gcc?
    – user590028
    Feb 10 '15 at 3:23










  • Can you post your code ? Are you using Makefile provided in /lib/module ?
    – Parham Alvani
    Feb 10 '15 at 4:11










  • Well, I have a few things to report. For one, init.h and module.h seem to have vanished. Further, I tried to fix this issue, and things.. somehow went wrong. I tried using the command "sudo apt-get install linux-headers-generic," and it gave me an error message: "E: Package 'linux-headers-generic' has no installation candidate."
    – Robert Crawford
    Feb 10 '15 at 4:20










  • I am not using the Makefile that you're talking about, but there is one in the directory of the module I'm trying to run. As for posting the code, there is a LOT of filler stuff in between that isn't really important... I'll work on getting it posted; I have it running on a virtual machine.
    – Robert Crawford
    Feb 10 '15 at 4:59
















Where is your copy of init.h, and what is the include path your passing to gcc?
– user590028
Feb 10 '15 at 3:23




Where is your copy of init.h, and what is the include path your passing to gcc?
– user590028
Feb 10 '15 at 3:23












Can you post your code ? Are you using Makefile provided in /lib/module ?
– Parham Alvani
Feb 10 '15 at 4:11




Can you post your code ? Are you using Makefile provided in /lib/module ?
– Parham Alvani
Feb 10 '15 at 4:11












Well, I have a few things to report. For one, init.h and module.h seem to have vanished. Further, I tried to fix this issue, and things.. somehow went wrong. I tried using the command "sudo apt-get install linux-headers-generic," and it gave me an error message: "E: Package 'linux-headers-generic' has no installation candidate."
– Robert Crawford
Feb 10 '15 at 4:20




Well, I have a few things to report. For one, init.h and module.h seem to have vanished. Further, I tried to fix this issue, and things.. somehow went wrong. I tried using the command "sudo apt-get install linux-headers-generic," and it gave me an error message: "E: Package 'linux-headers-generic' has no installation candidate."
– Robert Crawford
Feb 10 '15 at 4:20












I am not using the Makefile that you're talking about, but there is one in the directory of the module I'm trying to run. As for posting the code, there is a LOT of filler stuff in between that isn't really important... I'll work on getting it posted; I have it running on a virtual machine.
– Robert Crawford
Feb 10 '15 at 4:59




I am not using the Makefile that you're talking about, but there is one in the directory of the module I'm trying to run. As for posting the code, there is a LOT of filler stuff in between that isn't really important... I'll work on getting it posted; I have it running on a virtual machine.
– Robert Crawford
Feb 10 '15 at 4:59












3 Answers
3






active

oldest

votes

















up vote
4
down vote













I think you must first install something like linux-headers-[kernel version] by apt-get then you must create Makefile as following :



ifneq ($(KERNELRELEASE),)
# call from kernel build system
lifo-objs := main.o
obj-m := lifo.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
echo $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
$(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
endif

clean:
rm -rf *.o *~ core .depend *.mod.o .*.cmd *.ko *.mod.c
.tmp_versions *.markers *.symvers modules.order

depend .depend dep:
$(CC) $(CFLAGS) -M *.c > .depend

ifeq (.depend,$(wildcard .depend))
include .depend
endif


set KERNELDIR variable in above Makefile to your appropriate kernel version, by default it use your running kernel. If you use this Makefile you need to change your include to following format:



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


I think for kernel module developing use standard kernel from Linus Torvalds git is better. For some simple kernel module see this.






share|improve this answer























  • Well, the thing about it is that this is for an assignment, thus we were given a correct makefile to download and put into the correct directory (which I did, since it already worked at least once) and I tried getting the headers... is that the exact input I'd need to put into the terminal?
    – Robert Crawford
    Feb 10 '15 at 6:34










  • no you must use uname -r first to get your kernel release then use something like sudo apt-get install linux-headers-3.13.0-24-generic to get kernel header for appropriate release.
    – Parham Alvani
    Feb 10 '15 at 6:45










  • yeah, that didn't work. like the comments above, it can't find what I'm trying to install
    – Robert Crawford
    Feb 10 '15 at 7:01










  • Ok please send me your uname -r output in comments.
    – Parham Alvani
    Feb 10 '15 at 7:11












  • It's really strange, now it seems to be working for no reason at all. I was trying to get it done before I met with my professor today, but didn't manage to. We opened it up this morning, ran it, got a bunch of errors, sure, but this wasn't one of them. Thanks for giving it a try!
    – Robert Crawford
    Feb 10 '15 at 16:42


















up vote
1
down vote













when building kernel modules you should use make files



obj-m := module_name.o

KERNELDIR ?= /lib/modules/$(shell uname -r)/build

all default: modules
install: modules_install

modules modules_install help clean:
$(MAKE) -C $(KERNELDIR) M=$(shell pwd) $@





share|improve this answer






























    up vote
    0
    down vote













    There's a typo in the first line of the full code "/usr/unclude..." that could be responsible for failure to find init.h






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28423477%2flinux-init-h-no-such-file-or-directory%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      4
      down vote













      I think you must first install something like linux-headers-[kernel version] by apt-get then you must create Makefile as following :



      ifneq ($(KERNELRELEASE),)
      # call from kernel build system
      lifo-objs := main.o
      obj-m := lifo.o
      else
      KERNELDIR ?= /lib/modules/$(shell uname -r)/build
      PWD := $(shell pwd)
      modules:
      echo $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
      $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
      endif

      clean:
      rm -rf *.o *~ core .depend *.mod.o .*.cmd *.ko *.mod.c
      .tmp_versions *.markers *.symvers modules.order

      depend .depend dep:
      $(CC) $(CFLAGS) -M *.c > .depend

      ifeq (.depend,$(wildcard .depend))
      include .depend
      endif


      set KERNELDIR variable in above Makefile to your appropriate kernel version, by default it use your running kernel. If you use this Makefile you need to change your include to following format:



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


      I think for kernel module developing use standard kernel from Linus Torvalds git is better. For some simple kernel module see this.






      share|improve this answer























      • Well, the thing about it is that this is for an assignment, thus we were given a correct makefile to download and put into the correct directory (which I did, since it already worked at least once) and I tried getting the headers... is that the exact input I'd need to put into the terminal?
        – Robert Crawford
        Feb 10 '15 at 6:34










      • no you must use uname -r first to get your kernel release then use something like sudo apt-get install linux-headers-3.13.0-24-generic to get kernel header for appropriate release.
        – Parham Alvani
        Feb 10 '15 at 6:45










      • yeah, that didn't work. like the comments above, it can't find what I'm trying to install
        – Robert Crawford
        Feb 10 '15 at 7:01










      • Ok please send me your uname -r output in comments.
        – Parham Alvani
        Feb 10 '15 at 7:11












      • It's really strange, now it seems to be working for no reason at all. I was trying to get it done before I met with my professor today, but didn't manage to. We opened it up this morning, ran it, got a bunch of errors, sure, but this wasn't one of them. Thanks for giving it a try!
        – Robert Crawford
        Feb 10 '15 at 16:42















      up vote
      4
      down vote













      I think you must first install something like linux-headers-[kernel version] by apt-get then you must create Makefile as following :



      ifneq ($(KERNELRELEASE),)
      # call from kernel build system
      lifo-objs := main.o
      obj-m := lifo.o
      else
      KERNELDIR ?= /lib/modules/$(shell uname -r)/build
      PWD := $(shell pwd)
      modules:
      echo $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
      $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
      endif

      clean:
      rm -rf *.o *~ core .depend *.mod.o .*.cmd *.ko *.mod.c
      .tmp_versions *.markers *.symvers modules.order

      depend .depend dep:
      $(CC) $(CFLAGS) -M *.c > .depend

      ifeq (.depend,$(wildcard .depend))
      include .depend
      endif


      set KERNELDIR variable in above Makefile to your appropriate kernel version, by default it use your running kernel. If you use this Makefile you need to change your include to following format:



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


      I think for kernel module developing use standard kernel from Linus Torvalds git is better. For some simple kernel module see this.






      share|improve this answer























      • Well, the thing about it is that this is for an assignment, thus we were given a correct makefile to download and put into the correct directory (which I did, since it already worked at least once) and I tried getting the headers... is that the exact input I'd need to put into the terminal?
        – Robert Crawford
        Feb 10 '15 at 6:34










      • no you must use uname -r first to get your kernel release then use something like sudo apt-get install linux-headers-3.13.0-24-generic to get kernel header for appropriate release.
        – Parham Alvani
        Feb 10 '15 at 6:45










      • yeah, that didn't work. like the comments above, it can't find what I'm trying to install
        – Robert Crawford
        Feb 10 '15 at 7:01










      • Ok please send me your uname -r output in comments.
        – Parham Alvani
        Feb 10 '15 at 7:11












      • It's really strange, now it seems to be working for no reason at all. I was trying to get it done before I met with my professor today, but didn't manage to. We opened it up this morning, ran it, got a bunch of errors, sure, but this wasn't one of them. Thanks for giving it a try!
        – Robert Crawford
        Feb 10 '15 at 16:42













      up vote
      4
      down vote










      up vote
      4
      down vote









      I think you must first install something like linux-headers-[kernel version] by apt-get then you must create Makefile as following :



      ifneq ($(KERNELRELEASE),)
      # call from kernel build system
      lifo-objs := main.o
      obj-m := lifo.o
      else
      KERNELDIR ?= /lib/modules/$(shell uname -r)/build
      PWD := $(shell pwd)
      modules:
      echo $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
      $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
      endif

      clean:
      rm -rf *.o *~ core .depend *.mod.o .*.cmd *.ko *.mod.c
      .tmp_versions *.markers *.symvers modules.order

      depend .depend dep:
      $(CC) $(CFLAGS) -M *.c > .depend

      ifeq (.depend,$(wildcard .depend))
      include .depend
      endif


      set KERNELDIR variable in above Makefile to your appropriate kernel version, by default it use your running kernel. If you use this Makefile you need to change your include to following format:



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


      I think for kernel module developing use standard kernel from Linus Torvalds git is better. For some simple kernel module see this.






      share|improve this answer














      I think you must first install something like linux-headers-[kernel version] by apt-get then you must create Makefile as following :



      ifneq ($(KERNELRELEASE),)
      # call from kernel build system
      lifo-objs := main.o
      obj-m := lifo.o
      else
      KERNELDIR ?= /lib/modules/$(shell uname -r)/build
      PWD := $(shell pwd)
      modules:
      echo $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
      $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
      endif

      clean:
      rm -rf *.o *~ core .depend *.mod.o .*.cmd *.ko *.mod.c
      .tmp_versions *.markers *.symvers modules.order

      depend .depend dep:
      $(CC) $(CFLAGS) -M *.c > .depend

      ifeq (.depend,$(wildcard .depend))
      include .depend
      endif


      set KERNELDIR variable in above Makefile to your appropriate kernel version, by default it use your running kernel. If you use this Makefile you need to change your include to following format:



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


      I think for kernel module developing use standard kernel from Linus Torvalds git is better. For some simple kernel module see this.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Feb 10 '15 at 7:13

























      answered Feb 10 '15 at 6:02









      Parham Alvani

      1,3301816




      1,3301816












      • Well, the thing about it is that this is for an assignment, thus we were given a correct makefile to download and put into the correct directory (which I did, since it already worked at least once) and I tried getting the headers... is that the exact input I'd need to put into the terminal?
        – Robert Crawford
        Feb 10 '15 at 6:34










      • no you must use uname -r first to get your kernel release then use something like sudo apt-get install linux-headers-3.13.0-24-generic to get kernel header for appropriate release.
        – Parham Alvani
        Feb 10 '15 at 6:45










      • yeah, that didn't work. like the comments above, it can't find what I'm trying to install
        – Robert Crawford
        Feb 10 '15 at 7:01










      • Ok please send me your uname -r output in comments.
        – Parham Alvani
        Feb 10 '15 at 7:11












      • It's really strange, now it seems to be working for no reason at all. I was trying to get it done before I met with my professor today, but didn't manage to. We opened it up this morning, ran it, got a bunch of errors, sure, but this wasn't one of them. Thanks for giving it a try!
        – Robert Crawford
        Feb 10 '15 at 16:42


















      • Well, the thing about it is that this is for an assignment, thus we were given a correct makefile to download and put into the correct directory (which I did, since it already worked at least once) and I tried getting the headers... is that the exact input I'd need to put into the terminal?
        – Robert Crawford
        Feb 10 '15 at 6:34










      • no you must use uname -r first to get your kernel release then use something like sudo apt-get install linux-headers-3.13.0-24-generic to get kernel header for appropriate release.
        – Parham Alvani
        Feb 10 '15 at 6:45










      • yeah, that didn't work. like the comments above, it can't find what I'm trying to install
        – Robert Crawford
        Feb 10 '15 at 7:01










      • Ok please send me your uname -r output in comments.
        – Parham Alvani
        Feb 10 '15 at 7:11












      • It's really strange, now it seems to be working for no reason at all. I was trying to get it done before I met with my professor today, but didn't manage to. We opened it up this morning, ran it, got a bunch of errors, sure, but this wasn't one of them. Thanks for giving it a try!
        – Robert Crawford
        Feb 10 '15 at 16:42
















      Well, the thing about it is that this is for an assignment, thus we were given a correct makefile to download and put into the correct directory (which I did, since it already worked at least once) and I tried getting the headers... is that the exact input I'd need to put into the terminal?
      – Robert Crawford
      Feb 10 '15 at 6:34




      Well, the thing about it is that this is for an assignment, thus we were given a correct makefile to download and put into the correct directory (which I did, since it already worked at least once) and I tried getting the headers... is that the exact input I'd need to put into the terminal?
      – Robert Crawford
      Feb 10 '15 at 6:34












      no you must use uname -r first to get your kernel release then use something like sudo apt-get install linux-headers-3.13.0-24-generic to get kernel header for appropriate release.
      – Parham Alvani
      Feb 10 '15 at 6:45




      no you must use uname -r first to get your kernel release then use something like sudo apt-get install linux-headers-3.13.0-24-generic to get kernel header for appropriate release.
      – Parham Alvani
      Feb 10 '15 at 6:45












      yeah, that didn't work. like the comments above, it can't find what I'm trying to install
      – Robert Crawford
      Feb 10 '15 at 7:01




      yeah, that didn't work. like the comments above, it can't find what I'm trying to install
      – Robert Crawford
      Feb 10 '15 at 7:01












      Ok please send me your uname -r output in comments.
      – Parham Alvani
      Feb 10 '15 at 7:11






      Ok please send me your uname -r output in comments.
      – Parham Alvani
      Feb 10 '15 at 7:11














      It's really strange, now it seems to be working for no reason at all. I was trying to get it done before I met with my professor today, but didn't manage to. We opened it up this morning, ran it, got a bunch of errors, sure, but this wasn't one of them. Thanks for giving it a try!
      – Robert Crawford
      Feb 10 '15 at 16:42




      It's really strange, now it seems to be working for no reason at all. I was trying to get it done before I met with my professor today, but didn't manage to. We opened it up this morning, ran it, got a bunch of errors, sure, but this wasn't one of them. Thanks for giving it a try!
      – Robert Crawford
      Feb 10 '15 at 16:42












      up vote
      1
      down vote













      when building kernel modules you should use make files



      obj-m := module_name.o

      KERNELDIR ?= /lib/modules/$(shell uname -r)/build

      all default: modules
      install: modules_install

      modules modules_install help clean:
      $(MAKE) -C $(KERNELDIR) M=$(shell pwd) $@





      share|improve this answer



























        up vote
        1
        down vote













        when building kernel modules you should use make files



        obj-m := module_name.o

        KERNELDIR ?= /lib/modules/$(shell uname -r)/build

        all default: modules
        install: modules_install

        modules modules_install help clean:
        $(MAKE) -C $(KERNELDIR) M=$(shell pwd) $@





        share|improve this answer

























          up vote
          1
          down vote










          up vote
          1
          down vote









          when building kernel modules you should use make files



          obj-m := module_name.o

          KERNELDIR ?= /lib/modules/$(shell uname -r)/build

          all default: modules
          install: modules_install

          modules modules_install help clean:
          $(MAKE) -C $(KERNELDIR) M=$(shell pwd) $@





          share|improve this answer














          when building kernel modules you should use make files



          obj-m := module_name.o

          KERNELDIR ?= /lib/modules/$(shell uname -r)/build

          all default: modules
          install: modules_install

          modules modules_install help clean:
          $(MAKE) -C $(KERNELDIR) M=$(shell pwd) $@






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 27 at 23:31









          sotona

          7131323




          7131323










          answered Mar 27 at 20:48









          izak

          112




          112






















              up vote
              0
              down vote













              There's a typo in the first line of the full code "/usr/unclude..." that could be responsible for failure to find init.h






              share|improve this answer

























                up vote
                0
                down vote













                There's a typo in the first line of the full code "/usr/unclude..." that could be responsible for failure to find init.h






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  There's a typo in the first line of the full code "/usr/unclude..." that could be responsible for failure to find init.h






                  share|improve this answer












                  There's a typo in the first line of the full code "/usr/unclude..." that could be responsible for failure to find init.h







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 11 '16 at 10:17









                  GEphil

                  12




                  12






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28423477%2flinux-init-h-no-such-file-or-directory%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                      Alcedinidae

                      Can an atomic nucleus contain both particles and antiparticles? [duplicate]