1

This is my simple drivers Makefile:

obj-m+=hello_world_module.o
KDIR=/lib/modules/$(shell uname -r)/build
all:
    make -C $(KDIR) M=$(shell pwd) modules  
clean:
    make -C $(KDIR) M=$(shell pwd) clean

and the driver code is:

enter image description here

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

static int __hello_world_init(void)
{
    printf(KERN_INFO "Hello world\n");
    printf(KERN_INFO "module inserted\n");
    return 0;
}

void __exit hello_world_exit(void)
{
    printf(KERN_INFO "module removed\n");
    printf("exit\n");
}

module_init(hello_world_init);
module_exit(hello_world_exit);
MODULE_AUTHOR("Sridhar G");

When I run sudo make I get this error:

enter image description here

make -C /lib/modules/4.15.0-30-generic/build M=/home/sridhar/Documents
/DD/hello_world_module modules  
make[1]: Entering directory '/usr/src/linux-headers-4.15.0-30-generic'
  CC [M]  /home/sridhar/Documents/DD/hello_world_module/hello_world_module.o
cc1: error: code model kernel does not support PIC mode
scripts/Makefile.build:339: recipe for target '/home/sridhar/Documents
/DD/hello_world_module/hello_world_module.o' failed
make[2]: *** [/home/sridhar/Documents/DD/hello_world_module
/hello_world_module.o] Error 1
Makefile:1552: recipe for target '_module_/home/sridhar/Documents
/DD/hello_world_module' failed
make[1]: *** [_module_/home/sridhar/Documents/DD/hello_world_module] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-30-generic'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.