Unlike user-space applications, the kernel cannot invoke standard C libraries or any other libraries that are not part of the kernel. The main reason is the speed and size limits.
The standard C library is too big for the kernel.
Many of the commonly used LIBC functions have been implemented in the kernel. The library files in the kernel are stored in the root directory of the kernel under the Lib directory.
As the commonly used string manipulation functions are defined in LIB/STRING.C, the host needs to include the header file <linux/string.h> into the call.
With regard to the kernel's header file, the kernel cannot contain header files outside the kernel, as if the kernel cannot call libraries outside the kernel.
1) The basic header file is placed in the kernel's include/directory, such as the following referenced header file
#include <linux/i2c.h>
Located in Include/linux/i2c.h
2) the platform-related header files are located under Arch/<architecture>/include/asm, prefixed with asm/when the header files are included, as follows:
#include <asm/ioctl.h>
printf () cannot be called in the kernel, but the kernel provides PRINTK () for us to use.
PRINTK () is similar to the use of printf (), as follows:
PRINTK ("Hello world! A string '%s ' and an integer '%d ' \ n', str, i);
A notable difference between PRINTK () and printf () is that PRINTK () allows the use of priority tags. The priority flag is used by the SYSLOGD process to determine where to display
The kernel prints information. The following example:
" This was an error!\n ");
Note that there is no comma after the priority tag Kern_err.
Linux kernel header files and kernel library files