martinezjavier / ldd3

Linux Device Drivers 3 examples updated to work in recent kernels
http://examples.oreilly.com/9780596005900/
Other
2.35k stars 905 forks source link

*** No rule to make target 'Device'. Stop. #74

Closed z41dth3c0d3r closed 2 years ago

z41dth3c0d3r commented 2 years ago

My hello.c code

#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
    printk(KERN_ALERT "Hello, world\n");
    return 0;
}

static void hello_exit(void)
{
    printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);

and my makefile

LDDINC=$(PWD)/../include
EXTRA_CFLAGS += -I$(LDDINC)

ifeq ($(KERNELRELEASE),)

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

modules:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

modules_install:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install

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

.PHONY: modules modules_install clean

else
    obj-m := hello.o
endif

and the output when i run make

make -C /lib/modules/5.13.0-22-generic/build M=/mnt/Programming/Programming/Linux Device Driver Dev modules
make[1]: Entering directory '/usr/src/linux-headers-5.13.0-22-generic'
make[1]: *** No rule to make target 'Device'.  Stop.
make[1]: Leaving directory '/usr/src/linux-headers-5.13.0-22-generic'
make: *** [Makefile:10: modules] Error 2
Minoru commented 2 years ago

make is confused by the spaces in the path. Please try renaming your working directory to _Linux_device_Driver_Devmodules or something like that.

z41dth3c0d3r commented 2 years ago

Ok i've done that and right now i am using debian based distribution and now i got this!

and please note that path is /mnt/Programming/Programming/Linux_Device_Driver_Dev and not /mnt/Programming/Programming/Linux_Device_Driver_Dev_modules because in make -C /lib/modules/5.15.0-kali2-amd64/build M=/mnt/Programming/Programming/Linux_Device_Driver_Dev modules 'modules ' is in make file

make -C /lib/modules/5.15.0-kali2-amd64/build M=/mnt/Programming/Programming/Linux_Device_Driver_Dev modules
make[1]: Entering directory '/usr/src/linux-headers-5.15.0-kali2-amd64'
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: gcc-11 (Debian 11.2.0-12) 11.2.0
  You are using:           gcc-11 (Debian 11.2.0-13) 11.2.0
make[2]: *** No rule to make target '/mnt/Programming/Programming/Linux_Device_Driver_Dev/hello.o', needed by '/mnt/Programming/Programming/Linux_Device_Driver_Dev/hello.mod'.  Stop.
make[1]: *** [/usr/src/linux-headers-5.15.0-kali2-common/Makefile:1892: /mnt/Programming/Programming/Linux_Device_Driver_Dev] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.15.0-kali2-amd64'
make: *** [Makefile:10: modules] Error 2
z41dth3c0d3r commented 2 years ago

okay i got it

rajareddymittu commented 2 years ago

can you hlp me with the same error please