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

时间:2020-12-02 09:44:02

Let's say I want to use printk() within arch/x86/boot/string.c before compiling the kernel. Which header file do I have to include so that the linker knows where to find printk()? I tried #include <linux/kernel.h> and #include <linux/printk.h> but I always get errors during make bzImage telling me the linker does not find printk:

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

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

1 个解决方案

#1


4  

You are trying to instrument the boot stage of the kernel. It has its own really small library and doesn't have any headers like linux/printk.h available. The function is called printf() and it's implemented in arch/x86/boot/printf.c.

您正试图检测内核的启动阶段。它有自己非常小的库,没有像linux / printk.h这样的标题。该函数名为printf(),它在arch / x86 / boot / printf.c中实现。

The output of this function goes to the channel whatever defined in BIOS (int 10h) and, if asked, to the legacy (you can't use UART which has 32-bit I/O, for example) serial line. For the details refer to the printf.c source file.

此函数的输出将转到BIOS中定义的任何通道(int 10h),如果要求,则转到旧版(例如,不能使用具有32位I / O的UART)串行线。有关详细信息,请参阅printf.c源文件。

#1


4  

You are trying to instrument the boot stage of the kernel. It has its own really small library and doesn't have any headers like linux/printk.h available. The function is called printf() and it's implemented in arch/x86/boot/printf.c.

您正试图检测内核的启动阶段。它有自己非常小的库,没有像linux / printk.h这样的标题。该函数名为printf(),它在arch / x86 / boot / printf.c中实现。

The output of this function goes to the channel whatever defined in BIOS (int 10h) and, if asked, to the legacy (you can't use UART which has 32-bit I/O, for example) serial line. For the details refer to the printf.c source file.

此函数的输出将转到BIOS中定义的任何通道(int 10h),如果要求,则转到旧版(例如,不能使用具有32位I / O的UART)串行线。有关详细信息,请参阅printf.c源文件。