secondstriker
secondstriker

Reputation: 31

make: no rule to make target

i have written a simple linux module & its make file

this is my module

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

MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void) {
  printk("<1> Hello world!\n");
  return 0;
}

static void hello_exit(void) {
  printk("<1> Bye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);

this is my make file

    obj-m :=Hello.o


KDIR = /usr/src/linux-headers-3.5.0-17

all:
    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

clean: 
    rm -rf *.o *.ko *.mod.* *.symvers *.order

when i execute make -f MakeFile it gives following o/p

make -C /usr/src/linux-headers-3.5.0-17 SUBDIRS=/home/linux/Desktop modules
make[1]: Entering directory `/usr/src/linux-headers-3.5.0-17'

  WARNING: Symbol version dump /usr/src/linux-headers-3.5.0-17/Module.symvers
           is missing; modules will have no dependencies and modversions.

scripts/Makefile.build:44: /home/linux/Desktop/Makefile: No such file or directory
make[2]: *** No rule to make target `/home/linux/Desktop/Makefile'.  Stop.
make[1]: *** [_module_/home/linux/Desktop] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.5.0-17'
make: *** [all] Error 2

can any one tell me how to get rid of these errors. Thanks in advance

Upvotes: 2

Views: 31809

Answers (2)

Bhagirathsinh Gohil
Bhagirathsinh Gohil

Reputation: 673

obj-m += xyz.o

KDIR:=/usr/src/linux-headers-3.5.0-46-generic

all:

       make -C $(KDIR) M=$(PWD) modules

clean:

       make -C $(KDIR) M=$(PWD) clean

Are you sure /usr/src/ contains linux-headers-3.5.0-46-generic files? if this is not the case, download:

sudo apt-get install linux-headers-3.5.0-46

sudo apt-get install linux-headers-3.5.0-46-generic

Upvotes: 0

vinay hunachyal
vinay hunachyal

Reputation: 3891

Make the below change in your Makefile

First check which kernel is running by typing uname -a

Then go to cd /usr/src/

then check your linux source-code name

for e.g

uname -a Linux vinay-VirtualBox 3.2.0-50-generic-pae #76-Ubuntu SMP Tue Jul 9 19:24:55 UTC 2013 i686 i686 i386 GNU/Linux

here its source-code name is linux-headers-3.2.0-50-generic-pae same thing in your case e.g

linux-headers-3.2.0-23 linux-headers-3.2.0-23-generic-pae so use linux-headers-3.2.0-23-generic-pae instead of linux-headers-3.2.0-23 i.e replace same in your makefile

i.e KDIR=/usr/src/linux-headers-3.5.0-17-generic-pae

or in order to avoid above problem use
KDIR == /lib/modules/$(shell uname -r)/build

PWD := $(shell pwd)
KDIR == /lib/modules/$(shell uname -r)/build

$(MAKE) -C $(KDIR) M=$(PWD) modules

Upvotes: 2

Related Questions