【问题标题】:Which header file do I have to include to get printk() within a kernel source file?我必须包含哪个头文件才能在内核源文件中获取 printk()?
【发布时间】:2015-11-11 20:33:09
【问题描述】:

假设我想在编译内核之前在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`

【问题讨论】:

  • 很遗憾没有,我尝试包含#include <linux/printk.h>,但仍然出现错误。
  • 这与标题无关。链接有问题。先试试make clean
  • 阅读 this discussion 类似的主题...它似乎确实指向链接问题
  • 头文件与链接无关。您需要知道它在哪个库中并告诉链接器与该库链接(例如添加开关“-lSomeLibrary.a”)

标签: c linux gcc compiler-errors linux-kernel


【解决方案1】:

您正在尝试检测内核的引导阶段。它有自己非常小的库,并且没有像 linux/printk.h 这样的任何标题可用。该函数名为printf(),在arch/x86/boot/printf.c中实现。

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

【讨论】:

  • 好的,我明白了。 printf() 是否打印到屏幕上?
  • 您知道 ARM 架构的等效项吗?至少没有这样的文件。也许可以在/arch/arm/boot/compressed/misc.c 中使用putstr()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-02
  • 1970-01-01
  • 2014-11-10
  • 2012-04-14
  • 1970-01-01
  • 1970-01-01
  • 2016-11-16
相关资源
最近更新 更多