假设我想使用 printk()
在 arch/x86/boot/string.c
内在编译内核之前。我必须包含哪个头文件,以便链接器知道在哪里可以找到 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`
最佳答案
您正在尝试检测内核的启动阶段。它有自己的非常小的库,并且没有像 linux/printk.h
这样的头文件可用。该函数称为 printf()
,它在 arch/x86/boot/printf.c 中实现。
此函数的输出进入 BIOS 中定义的任何 channel (int 10h),如果被要求,则进入传统 channel (您不能使用具有 32 位 I/O 的 UART ,例如)串行线。有关详细信息,请参阅 printf.c 源文件。
关于c - 我必须包含哪个头文件才能在内核源文件中获取 printk()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32080310/