problem background
using Makefile to complete the compilation of Linux kernel module programs, there is a problem
Code structure
|-firewall
|------log.h
|------log.c
|------demo.c // log.h
|------Makefile
Makefile
File
ifneq ($(KERNELRELEASE),)
obj-m += firewall.o
firewall-objs := demo.o log.o
else
KDIR := /lib/modules/$(shell uname -r)/build
PWD:= $(shell pwd)
SUBDIRS := log
all:
make -C $(KDIR) M=$(PWD) modules
clean:
rm -f *.ko *.o *.mod.o *.mod.c *.symvers
endif
error
make -C /lib/modules/3.10.0-693.el7.x86_64/build M=/root/work/firewall/source modules
make[1]: "/usr/src/kernels/3.10.0-693.el7.x86_64"
CC [M] /root/work/firewall/source/demo.o
In file included from /root/work/firewall/source/demo.c:7:0:
/root/work/firewall/source/log.h:4:19: :stdio.h:
-sharpinclude <stdio.h>
^
make[2]: *** [/root/work/firewall/source/demo.o] 1
make[1]: *** [_module_/root/work/firewall/source] 2
make[1]: "/usr/src/kernels/3.10.0-693.el7.x86_64"
make: *** [all] 2
from the above, we can see the reason for the error fatal error: stdio.h: does not have that file or directory
, but the system contains stdio.h
files in
find / -name "stdio.h"
/usr/include/bits/stdio.h
/usr/include/stdio.h
and the execution of gcc-c test.c
is successful. The contents of the file are as follows
/*
*@file test.c stdio.h
*/
-sharpinclude <stdio.h>
int main() {
}
problem
to sum up, the root cause is not the lack of stdio.h
file, but the problem with the Makefile file. Which god can give us some advice? ( typing is not easy, if you are the one )