我正在尝试编译一个设备驱动程序,但是我得到了下面的错误,以及下面所有标题的相同错误
ddd@ddd:~/Desktop$ make
make -C /lib/modules/4.13.0-19-generic/build M=/home/ddd/Desktop modules
make[1]: Entering directory '/usr/src/linux-headers-4.13.0-19-generic'
CC [M] /home/ddd/Desktop/message_slot.o
/home/ddd/Desktop/message_slot.c:23:10: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^~~~~~~~~
compilation terminated.
scripts/Makefile.build:309: recipe for target '/home/ddd/Desktop/message_slot.o' failed
make[2]: *** [/home/ddd/Desktop/message_slot.o] Error 1
Makefile:1546: recipe for target '_module_/home/ddd/Desktop' failed
make[1]: *** [_module_/home/ddd/Desktop] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.13.0-19-generic'
Makefile:5: recipe for target 'all' failed
make: *** [all] Error 2
ddd@ddd:~/Desktop$ 我使用以下makefile编译程序:
obj-m := message_slot.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean问题是,通过运行小的.c代码:
#include <stdio.h>
#include <stdli.h>
int main(){
printf("test");
}用命令
gcc试验.c -o试验
一切都在汇编。我怀疑这是带有内核头的东西,但我已经下载了指定的所有头。我在运行lubuntu 17.10
我是不是遗漏了什么?
非常感谢
发布于 2017-12-09 09:50:20
stdio.h是用户空间头文件,而不是内核空间,这就是make失败的原因。在驱动程序中,为什么我们包含所有的headers,因为bcz没有main()函数,对吗?
当你要做make时,观察你的makefile
obj-m := message_slot.o
KDIR := /lib/modules/$(shell uname -r)/build 这意味着您正在编译为一个模块,您的源代码将在/usr/src/linux-4(某些版本)中。
如:
#include <linux/stat.h> 不
#include <stat.h>和
xyz@xyz-PC:/usr/src/linux-4.1.39/include/linux$ ls -l stdio.h
ls: cannot access stdio.h: No such file or directory为什么在您的驱动程序中包括stdio.h,因为您不使用printf,而是printk()?
是的,在应用程序中,您可以包括stdio.h,因为您使用gcc编译器作为file编译,而不是作为module编译。
希望能帮上忙。
https://stackoverflow.com/questions/47727135
复制相似问题