我必须包含哪个头文件才能在内核源文件中获取 printk()?

Which header file do I have to include to get printk() within a kernel source file?

假设我想在编译内核之前在 arch/x86/boot/string.c 中使用 printk()。我必须包含哪个头文件,以便链接器知道在哪里可以找到 printk()?我尝试了 #include <linux/kernel.h>#include <linux/printk.h>,但在 make bzImage 期间我总是遇到错误,告诉我链接器找不到 printk:

arch/x86/boot/compressed/string.o: In function `memcmp`:
string.c:(.text+0x19): undefined reference to `printk`

您正在尝试检测内核的启动阶段。它有自己的非常小的库,并且没有 headers 之类的 linux/printk.h 可用。该函数称为 printf() 并在 arch/x86/boot/printf.c.

中实现

此函数的输出进入 BIOS 中定义的任何通道 (int 10h),如果被要求,则进入传统通道(您不能使用具有 32 -bit I/O,例如)串行线。有关详细信息,请参阅 printf.c 源文件。