Compile linux kernel (2.6) module including non kernel headers
The kernel cannot use userspace code and must stand alone (i.e. be completely self contained, no libraries), therefore it does not pick up standard headers.
It is not clear what benefit trying to pick up userspace headers is. If there are things in there that it would be valid to use (constants, some macros perhaps provided they don't call any userspace functions), then it may be better to duplicate them and include only the kernel-compatible parts that you need.
It is not possible to link the kernel with libraries designed for userspace use - even if they don't make any OS calls - because the linking environment in the kernel cannot pick them up.
Instead, recompile any functions to be used in the kernel (assuming they don't make any OS or library calls - e.g. malloc - in which case they'll need to be modified anyway). Incorporate them into your own library to be used in your kernel modules.
Recent versions of linux contain cryptographic functions anyway, including various SHA hashes - perhaps you can use one of those instead.
Another idea would be to stop trying to do crypto in kernel-space and move the code to userspace. Userspace code is easier to write / debug / maintain etc.
Compile a linux 2.6 kernel module with newer compiler
Your kernel version is too old and it is missing linux/compiler-gcc5.h
.
The header is included from linux/compiler-gcc.h and its name is generated by preprocessor macro based on current compiler version:
#define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)
This header was introduced around version 3.18
.
You might try to get this file from a newer kernel source and put in into include/linux
.
Compiling Linux kernel module using gcc with kernel header files
This is additional info to delve into. Post 2.6 version, as mentioned in other reply the Makefile takes care of most of the Linux kernel module compilation steps. However, at the core of it is still GCC, and this is how it does: (you too may compile it without Makefile)
Following GCC options are necessary:
-isystem /lib/modules/`uname -r`/build/include: You must use the kernel headers of the kernel you're compiling against. Using the
default /usr/include/linux won't work.-D__KERNEL__: Defining this symbol tells the header files that the code will be run in kernel mode, not as a user process.
-DMODULE: This symbol tells the header files to give the appropriate definitions for a kernel module.
gcc -DMODULE -D__KERNEL__ -isystem /lib/modules/$(uname -r)/build/include -c hello.c -o hello.ko
How to extract kernel headers for compiling kernel module later
Create kernel packages instead, that's "make deb-pkg" for dpkg based distros and "make rpm-pkg" for RPM based ones. These create multiple packages, one of those is a package usable for external modules building. That should be linux-headers-* for the Debian packages and a "devel" package for he RPM versions.
Related Topics
Does 'Dash' Support 'Bash' Style Arrays
Loop Over File Names from 'Find'
Getmodulehandle(Null) on Linux
Split Delimited File into Smaller Files by Column
Setting the Thread /Proc/Pid/Cmdline
How to Import Environment Settings into My Perl Program
Pkill Returns 255 in Combination with Another Command via Remote Ssh
Difference Between Linux Kernel and Unix Kernel(Such as Freebsd) from Programmer's Point of View
Ignoring Comma in Field of CSV File with Awk
How Can a Process Try to Access Other Process's Memory in Linux Virtual Memory System
What Happened to Socket If Network Has Broken Down
Bluetooth Error: Native Library Bluecove_Arm Not Available
Access Bash Positional Parameter Through Variable
How to Pass Command Line Parameters with Quotes Stored in Single Variable