Compiling Kernel Error: Stdio.H: No Such File or Directory

error: stdio.h: No such file or directory error during make

Your way of building your program is the way to build kernel module and not c program application. and stdio.h does not exist in the environment of the kernel development so that's why you get the error:

error: "stdio.h: No such file or directory" error 

1) If you want to build a linux application then your Makefile is wrong:

You should modify your Makefile

Use the following Makefile:

all: hello

test: test.c
gcc -o hello hello.c

clean:
rm -r *.o hello

2) If you want to build a kernel module then your c code is wrong

  • YOU CAN NOT use stdio.h in the kernel space development. Itdoes not
    exist in the environment of the kernel development so that's why you
    get the error
  • YOU CAN NOT use main() in the kernel module C code
  • YOU CAN NOT use printf() in the kernel module C code

INSTEAD of using stdio.h, you have to use the following include

#include <linux/module.h>   /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */

INSTEAD of using int main() {, you have to use

int init_module(void) {

INSTEAD of using printf() use printk()

Use the following hello module instead of your hello code

/*  
* hello-1.c - The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */

int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");

/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}

void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}

Please refer to the following link for more detail about kernel module development

Compiling kernel error: stdio.h: No such file or directory

I do'nt see any io functions used in your code, so you don't need to include stdio.h

GCC fatal error: stdio.h: No such file or directory

macOS

I had this problem too (encountered through Macports compilers). Previous versions of Xcode would let you install command line tools through xcode/Preferences, but xcode5 doesn't give a command line tools option in the GUI, that so I assumed it was automatically included now. Try running this command:

xcode-select --install

If you see an error message that developer tools are already installed (and still header files can't be found), wipe out any existing one to do a fresh installation:

sudo rm -rf /Library/Developer/CommandLineTools

Ubuntu

(as per this answer)

sudo apt-get install libc6-dev

Alpine Linux

(as per this comment)

apk add libc-dev

Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error

There are three ways to solve this issue.

  1. Ignore Precompiled Headers #1
    Steps: Project > Properties > Configuration Properties > C/C++ > Command Line > in the Additional Options box add /Y-. (Screenshot of Property Pages) > Ok > Remove #include "stdafx.h"
  2. Ignore Precompiled Headers #2
    Steps: File > New > Project > ... > In the Application Wizard Window click Next > Uncheck the Precompiled Header box > Finish > Remove #include "stdafx.h"
  3. Reinstall Visual Studio
    This also worked for me, because I realized that maybe there was something wrong with my Windows SDK. I was using Windows 10, but with Windows SDK 8.1. You may have this problem as well.

    Steps: Open Visual Studio Installer > Click on the three-lined Menu Bar > Uninstall > Restart your computer > Open Visual Studio Installer > Install what you want, but make sure you install only the latest Windows SDK 10, not multiple ones nor the 8.1.

    The first time I installed Visual Studio, I would get an error stating that I needed to install Windows SDK 8.1. So I did, through Visual Studio Installer's Modify option. Perhaps this was a problem because I was installed it after Visual Studio was already installed, or because I needed SDK 10 instead. Just to be safe I did a complete reinstall.



Related Topics



Leave a reply



Submit