Centos7 kernel module compilation error

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 )

Mar.10,2021

you cannot reference stdio.h in kernel modules, because it is only used in applications, and its implementation depends on

.
  1. GNU libc, https://www.gnu.org/software/.
  2. or musl libc, https://www.musl-libc.org/

and other third party libraries.

  • The centos7 kernel interacts with the user mode through the / proc file

    question background is now writing a firewall project based on Linux netfilter . There are some questions about the interaction between kernel and user mode programs . Program environment centos7(3.10) gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (G...

    Mar.10,2021
  • Stat function segment error

    Environment centos7 programming language c Today, there is an error reading folders with the stat function. At first, the folder name is returned as-1. Later, it is found that the absolute path is needed. After the combination of the file name and pa...

    Mar.12,2021
Menu