Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

linux - Why is my hello-1.c and Makefile not producing .ko files?

I am following the Linux Kernel Module Programming Guide's hello world programming examples (pg 8-9): https://tldp.org/LDP/lkmpg/2.6/lkmpg.pdf

I have the following hello-1.c as described in the guide:

/*
 * hello?1.c ? The simplest kernel module.
 */
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */

int init_module(void) {
    printk(KERN_INFO "Hello world 1.
");
    /*
    * A non 0 return means init_module failed; module can't be loaded.
    */
    return 0;
}

void cleanup_module(void) {
    printk(KERN_INFO "Goodbye world 1.
");
}

Along with the Makefile on page 9:

obj?m += hello?1.o

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

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

When I use the Makefile with make, I get the following output:

make -C /lib/modules/5.4.0-60-generic/build M=/home/joeyoneill/Desktop/CSCI614 modules
make[1]: Entering directory '/usr/src/linux-headers-5.4.0-60-generic'
  Building modules, stage 2.
  MODPOST 0 modules
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-60-generic'

and 2 files (Module.symvers and modules.order) are made.

However, I do not get:

hostname:~/lkmpg?examples/02?HelloWorld# make
make ?C /lib/modules/2.6.11/build M=/root/lkmpg?examples/02?HelloWorld modules
make[1]: Entering directory `/usr/src/linux?2.6.11'
 CC [M] /root/lkmpg?examples/02?HelloWorld/hello?1.o
 Building modules, stage 2.
 MODPOST
 CC /root/lkmpg?examples/02?HelloWorld/hello?1.mod.o
 LD [M] /root/lkmpg?examples/02?HelloWorld/hello?1.ko
make[1]: Leaving directory `/usr/src/linux?2.6.11'
hostname:~/lkmpg?examples/02?HelloWorld#

Which is the output that the book gives and so I am not creating this .o or .ko file. Shown with the lines:

 CC /root/lkmpg?examples/02?HelloWorld/hello?1.mod.o
 LD [M] /root/lkmpg?examples/02?HelloWorld/hello?1.ko

Can anyone tell me what I am doing wrong?

question from:https://stackoverflow.com/questions/65877692/why-is-my-hello-1-c-and-makefile-not-producing-ko-files

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...