I\'m trying to compile the following program in Ubuntu. But I keep getting the error: \"stdio.h: No such file or directory\" error.
#include
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
stdio.h in the kernel space development. Itdoes not
exist in the environment of the kernel development so that's why you
get the errormain() in the kernel module C codeprintf() in the kernel module C codeINSTEAD of using stdio.h, you have to use the following include
#include /* Needed by all modules */
#include /* 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 /* Needed by all modules */
#include /* 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