日期:2014-05-16  浏览次数:21356 次

linux/init.h: No such file or directory
一直做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


------解决方案--------------------
兄弟,你这个是 驱动代码, 是不能这么编译的。。
写个 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
------解决方案--------------------
搞内核模块开发,内核头文件是首先要装上的