编译树外 Linux 内核模块时如何解决 stdarg.h No such file or directory 问题?

Mic*_*elT 10 linux

我有一个需要编译的树外 Linux 内核模块。当我在内核模块目录中执行“make”时,我得到:

"fatal error: stdarg.h: No such file or directory"

在开始构建之前,我安装了基于我的 Linux 发行版的头文件。

$sudo apt-get install kernel-headers-$(uname -r)

我该如何解决这个编译错误?(我的发行版是 Ubuntu 16.04,带有 linux-headers-4.15.0-42-generic)

Mic*_*elT 5

我使用“locate”命令搜索了 stdarg.h,看看是否可以在系统上运行该文件。

我有:

/usr/include/c++/5/tr1/stdarg.h

/usr/lib/gcc/i686-linux-gnu/5/include/cross-stdarg.h

/usr/lib/gcc/i686-linux-gnu/5/include/stdarg.h

...

它告诉我编译器至少提供了一个 stdarg.h 。

我尝试在内核模块 Makefile 中包含路径“/usr/lib/gcc/i686-linux-gnu/5/include”,以便可以获取 stdarg.h。它不起作用(在构建时,官方内核头中对 stdarg.h 的另一个引用未得到解析)。

我终于在下面直接创建了一个符号链接: /usr/src/linux-headers-4.15.0-42-generic/include

$sudo ln -s /usr/lib/gcc/i686-linux-gnu/5/include/stdarg.h stdarg.h

这足以解决编译问题。

我想知道内核头文件是否应该默认带有 stdarg.h 的实现(这是我第一次遇到这个问题)。我还读到编译器提供了一种实现,大多数时候最好使用编译器版本。

更新说明:如果上述解决方案仍然不能解决问题:

再次运行 make 之前,请执行 make clean。在文件夹中执行 als -la 并查找“.cache.mk”文件。如果它仍然存在,请将其删除并再次运行“make”。它应该可以解决问题。