1

is it possible to compile a kernel module on a live USB stick with Ubuntu 14.04 LTS? I have now tried for hours but all my attempts have failed.

What i've done. Installed the linux headers. Created a make file containing:

obj-m = hello.o
KVERSION = $(shell uname -r)
all:
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

created a c file and added

#include <linux/module.h>       /* Needed by all modules */
#include <linux/kernel.h>       /* Needed for KERN_INFO */
#include <linux/init.h>         /* Needed for the macros */
static int __init hello_start(void)
{
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;
}
static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye Mr.\n");
}
module_init(hello_start);
module_exit(hello_end);

When i write "make hello" i get the responds:

ubuntu@ubuntu:~/Desktop/EmbeddedProgramming$ make hello
cc     hello.c   -o hello
hello.c:1:60: fatal error: linux/module.h: No such file or directory
 #include <linux/module.h>       /* Needed by all modules */

When i check uname -r i get back "3.16.0-30-generic". When i check the directory i can indeed find the module.h in that location. I got no idea why it say it cannot find the header file because it is there.

6
  • 1
    Please edit your question to tell us what you are trying to compile and what steps you have tried so far.
    – chili555
    Feb 26, 2015 at 19:20
  • Sry, added more info now-
    – Eric
    Feb 26, 2015 at 19:28
  • My copy of linux/module.h is in linux-headers. Did you first install linux-headers-generic or otherwise matching your running kernel?
    – chili555
    Feb 26, 2015 at 19:50
  • Yes, i believe so.
    – Eric
    Feb 26, 2015 at 19:53
  • If cc hello.c -o hello is the exact command being run, then it won't work. You need to use the -I flag to specify that that directory should be included in the search for header files. Also, note that implicit rules are at play here. See this page. Feb 26, 2015 at 20:30

1 Answer 1

1

I ran the wrong command in Terminal, it should be make -C /lib/modules/$(uname -r)/build M=$(pwd) modules It does work now.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .