How to solve error: linux/module.h: No such file or directory in C ?

Sometimes when we execute a C program, we face an error message “No such file or directory” when the system is not able to find any header file.

1. Error message while compiling a C program

[root@nglinux ~]# gcc -o kernpanic kernel_panic.c 
kernel_panic.c:5:57: error: linux/module.h: No such file or directory

2. Find if any header file available on your system

[root@nglinux ~]# find / -print | grep -i 'module.h'
/usr/lib/pulse-0.9.21/modules/module-http-protocol-unix.so
/usr/lib/pulse-0.9.21/modules/module-http-protocol-tcp.so
/usr/lib/pulse-0.9.21/modules/module-hal-detect.so
/usr/share/doc/git-1.7.1/git-submodule.html
/usr/src/kernels/2.6.32-696.el6.i686/include/trace/events/module.h
/usr/src/kernels/2.6.32-696.el6.i686/include/drm/ttm/ttm_module.h
/usr/src/kernels/2.6.32-696.el6.i686/include/asm-generic/module.h
/usr/src/kernels/2.6.32-696.el6.i686/include/linux/module.h
/usr/src/kernels/2.6.32-696.el6.i686/arch/x86/include/asm/module.h
/usr/src/debug/kernel-2.6.32-754.el6/linux-2.6.32-754.el6.i686/tools/perf/util/include/linux/module.h
/usr/src/debug/kernel-2.6.32-754.el6/linux-2.6.32-754.el6.i686/drivers/edac/edac_module.h
/usr/src/debug/kernel-2.6.32-754.el6/linux-2.6.32-754.el6.i686/include/trace/events/module.h
/usr/src/debug/kernel-2.6.32-754.el6/linux-2.6.32-754.el6.i686/include/asm-generic/module.h
/usr/src/debug/kernel-2.6.32-754.el6/linux-2.6.32-754.el6.i686/include/linux/module.h

Solution

To solve this error message, we can mention the header file path using I option.

[root@nglinux ~]# gcc -o kernpanic -I /usr/src/debug/kernel-2.6.32-754.el6/linux-2.6.32-754.el6.i686/tools/perf/util/include/linux/ kernel_panic.c 

Leave a Reply

Your email address will not be published.