Linux kernel compilation - hello world

I am trying to compile the Linux kernel: http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html

I have a simple program hello world hello-1.cpp

#include <linux/module.h> #include <linux/kernel.h> int init_module(void) { return 0; } void cleanup_module(void) { } 

But I'm trying to create it using a Makefile:

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

I get a couple of errors.

 make -C /home/pacman/linux-2.6.34.11/2.6.35.6-45.fc14.i686/build M=/home/pacman/p1 modules make: *** /home/pacman/linux-2.6.34.11/2.6.35.6-45.fc14.i686/build: No such file or directory. Stop. 

make: * [all] Error 2

Am I forgetting to define something?

+6
source share
1 answer

Rename hello-1. cpp on hello-1. c (modules must be written in C) and add the lines:

 module_init(init_module); module_exit(cleanup_module); 
+1
source

Source: https://habr.com/ru/post/913752/


All Articles