'How can I solve stdarg.h No such file or directory while compiling out-of-tree Linux kernel module?

I have an out-of-tree Linux kernel module that I need to compile. When I execute "make" in the kernel module directory I am getting:

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

Before starting the build I installed the header file based on my Linux distribution.

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

How can I solve this compilation error? (my distribution is Ubuntu 16.04 with linux-headers-4.15.0-42-generic)



Solution 1:[1]

I ran a search of stdarg.h with the "locate" command to see if I can sport the file on the system.

I got:

/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

...

It tells me there is at least one stdarg.h provided by the compiler.

I tried to include the path "/usr/lib/gcc/i686-linux-gnu/5/include" in the kernel module Makefile so stdarg.h can be picked up. It did not work (while building, another reference to stdarg.h in the official kernel header was not being resolved).

I finally created a symlink directly under: /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

This was just enough to solve the compilation issue.

I am wondering if the kernel headers should come with an implementation of stdarg.h by default (that is the first time I encounter this issue). I have also read that the compiler provide one implementation and most of the time it is better to use the compiler version.

Updated note: if the above solution still does not solve the problem:

Before running make again, do a make clean. Do a ls -la in the folder and look for a ".cache.mk" file. If this is still there, remove it and run "make" again. It should solve the problem.

Solution 2:[2]

If you using Arch Linux with zen-kernel:

sudo CPATH=/usr/src/linux-zen/include/linux vmware-modconfig --console --install-all

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Lorenzo Morelli