gpt4 book ai didi

c - printk : too many arguments for format 的 Linux 内核模块错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:51:00 24 4
gpt4 key购买 nike

我在 /home/coder/workspace/test_module 目录中创建了 hello.cMakefile。我正在使用 arch linux。我已经安装了 linux-headers

你好.c

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


static int hello_init(void){
printk(KERN_ALERT, "hello, this is hello module");

return 0;
}

static void hello_exit(void){
printk(KERN_ALERT, "exiting the hello module");
}

module_init(hello_init);
module_exit(hello_exit);

生成文件

obj-m=hello.o

KDIR = /usr/lib/modules/$(shell uname -r)/build

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


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

错误

[coder@coder test_module]$ make
make -C /usr/lib/modules/4.10.13-1-ARCH/build M=/home/coder/workspace/test_module modules
make[1]: Entering directory '/usr/lib/modules/4.10.13-1-ARCH/build'
CC [M] /home/coder/workspace/test_module/hello.o
In file included from ./include/linux/printk.h:6:0,
from ./include/linux/kernel.h:13,
from ./include/linux/list.h:8,
from ./include/linux/module.h:9,
from /home/coder/workspace/test_module/hello.c:2:
/home/coder/workspace/test_module/hello.c: In function 'hello_init':
./include/linux/kern_levels.h:4:18: warning: too many arguments for format [-Wformat-extra-args]
#define KERN_SOH "\001" /* ASCII Start Of Header */
^
./include/linux/kern_levels.h:8:20: note: in expansion of macro 'KERN_SOH'
#define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
^~~~~~~~
/home/coder/workspace/test_module/hello.c:6:9: note: in expansion of macro 'KERN_ALERT'
printk(KERN_ALERT, "hello, this is hello module");
^~~~~~~~~~
/home/coder/workspace/test_module/hello.c: In function 'hello_exit':
./include/linux/kern_levels.h:4:18: warning: too many arguments for format [-Wformat-extra-args]
#define KERN_SOH "\001" /* ASCII Start Of Header */
^
./include/linux/kern_levels.h:8:20: note: in expansion of macro 'KERN_SOH'
#define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
^~~~~~~~
/home/coder/workspace/test_module/hello.c:12:9: note: in expansion of macro 'KERN_ALERT'
printk(KERN_ALERT, "exiting the hello module");
^~~~~~~~~~
Building modules, stage 2.
MODPOST 1 modules
CC /home/coder/workspace/test_module/hello.mod.o
LD [M] /home/coder/workspace/test_module/hello.ko
make[1]: Leaving directory '/usr/lib/modules/4.10.13-1-ARCH/build'

更多详情

$ uname -r
4.10.13-1-ARCH

$ ls -l /usr/lib/modules/$(uname -r)/build
drwxr-xr-x 4 root root 4096 Apr 27 15:47 Documentation
-rw-r--r-- 1 root root 252 Apr 27 15:47 Kconfig
-rw-r--r-- 1 root root 59062 Apr 27 15:47 Makefile
-rw-r--r-- 1 root root 1321690 Apr 27 15:47 Module.symvers
drwxr-xr-x 4 root root 4096 Apr 27 15:47 arch
drwxr-xr-x 3 root root 4096 Apr 27 15:47 block
drwxr-xr-x 2 root root 4096 Apr 27 15:47 certs
drwxr-xr-x 4 root root 4096 Apr 27 15:47 crypto
drwxr-xr-x 123 root root 4096 Apr 27 15:47 drivers
drwxr-xr-x 64 root root 4096 Apr 27 15:47 fs
drwxr-xr-x 21 root root 4096 Apr 27 15:47 include
drwxr-xr-x 2 root root 4096 Apr 27 15:47 init
drwxr-xr-x 8 root root 4096 Apr 27 15:47 kernel
drwxr-xr-x 4 root root 4096 Apr 27 15:47 lib
drwxr-xr-x 2 root root 4096 Apr 27 15:47 mm
drwxr-xr-x 58 root root 4096 Apr 27 15:47 net
drwxr-xr-x 2 root root 4096 Apr 27 15:47 samples
drwxr-xr-x 14 root root 4096 Apr 27 15:47 scripts
drwxr-xr-x 10 root root 4096 Apr 27 15:47 security
drwxr-xr-x 21 root root 4096 Apr 27 15:47 sound
drwxr-xr-x 3 root root 4096 Apr 27 15:47 tools
drwxr-xr-x 2 root root 4096 Apr 27 15:47 usr
drwxr-xr-x 4 root root 4096 Apr 27 15:47 virt
-rw-r--r-- 1 root root 20557744 Apr 27 15:46 vmlinux

我在这里做错了什么?

最佳答案

Loglevel 不是 printk() 的单独参数,它是消息的前缀。在你的情况下:

printk(KERN_ALERT "hello, this is hello module");

更多信息:https://en.wikipedia.org/wiki/Printk

关于c - printk : too many arguments for format 的 Linux 内核模块错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43915616/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com