错误:stdio.h中:化妆过程中没有这样的文件或目录错误 [英] error: stdio.h: No such file or directory error during make
问题描述
我试图编译在Ubuntu下面的程序。不过,我不断收到错误:stdio.h中:没有这样的文件或目录。误差
的#include<&stdio.h中GT;INT主要(无效)
{
的printf(世界,你好);
}
我的makefile文件是:
OBJ-M + = hello.o
所有:
使-I / usr / include目录-C / lib / modules目录/ $(壳使用uname -r)/建造M = $(PWD)模块
清洁:
使-C / lib / modules目录/ $(壳使用uname -r)/建造M = $(PWD)清洁
您构建计划的方法是建立内核模块,而不是C程序的应用程序的方式。和 stdio.h中
内核开发的环境不存在,所以这就是为什么你的错误:
错误:stdio.h中:没有这样的文件或目录错误
1)如果你想建立一个Linux应用程序,然后你的Makefile是错误的:
您应该修改你的Makefile
使用下面的Makefile:
所有:你好测试:test.c的
GCC -o你好的hello.c清洁:
RM -r *打招呼的.o
2)如果你想建立一个内核模块,然后你的c code是错误的。
- 你不能在内核空间的开发利用
stdio.h中
。它不是
存在于内核开发的环境,所以这就是为什么你
得到的错误 - 你不能使用
的main()
内核模块C中code - 你不能使用
的printf()
内核模块C中code
而不是是 stdio.h中
,你必须使用以下包含
的#include< Linux的/ - module.h中GT; / *所有模块所需* /
#包括LT&;的Linux / kernel.h> / *集所需的KERN_INFO * /
而不是使用 INT的main(){
,你必须使用
INT的init_module(无效){
而不是使用的printf()
使用的printk()
使用以下你好模块,而不是你打招呼code
/ *
* HELLO-1.C - 最简单的内核模块。
* /
#包括LT&; Linux的/ - module.h中GT; / *所有模块所需* /
#包括LT&;的Linux / kernel.h> / *集所需的KERN_INFO * /INT的init_module(无效)
{
printk的(KERN_INFO的Hello world 1 \\ n); / *
*非0的返回意味着init_module的失败;模块不能装载。
* /
返回0;
}虚空在cleanup_module(无效)
{
printk的(KERN_INFO再见世界1 \\ n);
}
请参考以下链接更多细节有关内核模块的开发
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 <stdio.h>
int main(void)
{
printf("Hello world");
}
My makefile is:
obj-m += hello.o
all:
make -I/usr/include -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
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
这篇关于错误:stdio.h中:化妆过程中没有这样的文件或目录错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!