LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Problem with compiling the module driver (https://www.linuxquestions.org/questions/programming-9/problem-with-compiling-the-module-driver-917154/)

Pouyaaa 12-04-2011 11:27 PM

Problem with compiling the module driver
 
I'm newbie at driver module programming.... I've written a very simple hello world module then I wanna compile it , I got this result :
Code:

make -C /lib/modules/2.6.38-8-generic/build M=/root/ker modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
make[1]: Makefile: No such file or directory
make[1]: *** No rule to make target `Makefile'.  Stop.
make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
make: *** [all] Error 2

Also I've installed linux headers via following command
Code:

apt-get install linux-headers-2.6.38-8-generic
here is my Makefile file
Code:

obj-m += hello.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules

clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean

Also I gotta note that , the "build" is not exist at that folder:)

my source code :

Code:

#include <linux/module.h>
#include <linux/kernel.h>
 
int init_module(void)
{
        printk(KERN_INFO "init_module() called\n");
        return 0;
}
 
void cleanup_module(void)
{
        printk(KERN_INFO "cleanup_module() called\n");
}

thanks

Meson 12-05-2011 01:47 AM

Is Makefile in the linux src directory? You might need a different package for Ubuntu.

Meson 12-05-2011 01:59 AM

Also, while we're at it. Your hello world should look more like this:

Code:

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

static int __init mymodule_init(void)
{
        printk(KERN_INFO "init_module() called\n");
        return 0;
}

static void __exit mymodule_exit(void)
{
        printk(KERN_INFO "cleanup_module() called\n");
}

module_init(mymodule_init);
module_exit(mymodule_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("me");
MODULE_DESCRIPTION("Hello, World!");


Pouyaaa 12-05-2011 03:35 AM

Sorry man , I got the problem solved by removing all of the linux source headers and re-install the proper one.... so all the lnk links are correct now :)

yeah I got that hello world missing lines added ;)

thanks


All times are GMT -5. The time now is 07:24 AM.