linux/init.h: No such file or directory

jiahehao 2010-07-14 03:20:21
一直做WINDOWS的编程。现在转向设备驱动。写了个例子。编译的时候报这个错?请问是要安装一个头文件包呢?还是要在编译的时候指定些什么?请说详细些,我这方面基础知识很少。正在学习中。。。

我的环境是redhat。还有一个问题是用gcc编译的时候系统是认的。但是我用gcc -o的时候,系统就说不认识这个参数了。请教诸位原因。

苦啊,这东西比VC6麻烦多了。。。。。。

[hpshu@china-sky ~]$ gcc mytest.c
mytest.c:1:24: error: linux/init.h: No such file or directory
mytest.c:2:26: error: linux/module.h: No such file or directory
mytest.c:4: error: expected declaration specifiers or ‘...’ before string constant
mytest.c: In function ‘MODULE_LICENSE’:
mytest.c:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
mytest.c:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
mytest.c:17: error: expected declaration specifiers before ‘module_init’
mytest.c:18: error: expected declaration specifiers before ‘module_exit’
mytest.c:18: error: expected ‘{’ at end of input
...全文
6251 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
lyjlddd 2012-09-10
  • 打赏
  • 举报
回复
楼主,问题解决没呢?我也碰到类似问题。刚刚开始学,不知道怎么改
lovekettysunny1314 2012-08-09
  • 打赏
  • 举报
回复
我也遇到这个问题呢,到底该如何解决 我用KDevelop写的
qzs939533967 2012-07-14
  • 打赏
  • 举报
回复
兄弟 你这行了不啊, 我也遇到这个问题,还没解决啊
kgdkhnw 2011-01-07
  • 打赏
  • 举报
回复
怎么看不到?
Tchely.Pan 2010-11-10
  • 打赏
  • 举报
回复
我也很郁闷,刚学驱动就是这样
monkey_kai 2010-08-12
  • 打赏
  • 举报
回复
你这个问题解决了么,我遇到个和你一样的问题
jiahehao 2010-07-15
  • 打赏
  • 举报
回复
thanks pottichu~~~~
Coder_Granger 2010-07-14
  • 打赏
  • 举报
回复
搞内核模块开发,内核头文件是首先要装上的
pottichu 2010-07-14
  • 打赏
  • 举报
回复 1
兄弟,你这个是 驱动代码, 是不能这么编译的。。
写个 makefile 就可以了。
记得命令前要用 Tab

fneq ($(KERNELRELEASE),)
#kbuild syntax. dependency relationshsip of files and target modules are listed here.
mymodule-objs := hello.o
obj-m := hello.o
else
PWD := $(shell pwd)
KVER ?= $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
all:
$(MAKE) -C $(KDIR) M=$(PWD)
clean:
rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions
endif



http://blog.csdn.net/pottichu/archive/2007/11/19/1892245.aspx
jiahehao 2010-07-14
  • 打赏
  • 举报
回复
以下是全部例子代码:
#include <linux/init.h>
#include <linux/module.h>

MODULE_LICENSE("Dual BSD/GPL")

static int hello_init(void)
{
printk(KERN_ALERT "Hello,world\n");
return 0;
}

static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye,cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);
jiahehao 2010-07-14
  • 打赏
  • 举报
回复
又试了下,gcc -o 系统是认识的。楼上你重复我报的错做啥,我知道是找某个头文件找不到。问题是我不知道这个头文件在哪,以及我如何把它包含进去。。。。。
steptodream 2010-07-14
  • 打赏
  • 举报
回复
mytest.c:1:24: error: linux/init.h: No such file or directory
mytest.c:2:26: error: linux/module.h: No such file or directory

4,465

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧