转自http://neilengineer.cublog.cn/
insmod: error inserting 'phyinfo.ko': -159951552 Success
make[2]: *** [/root/source/my-drivers/chartest/chartest.o] Error 1
make[1]: *** [_module_/root/source/my-drivers/chartest] Error 2
make[1]: Leaving directory `/root/source/linux-2.6.30.5'
make: *** [modules] Error 2
解决:
1、把#include <linux/config.h>修改为如下:
#define _LINUX_CONFIG_H
#include <linux/autoconf.h>
#endif
3、touch一个空的linux/config.h
/home/neil/source/my-drivers/char-simple/char-simple.c:158: warning: ?.lias?.attribute ignored
源码的一个函数实现时,少了一个“}”!!
1)函数实现时,EXPORT_SYMBOL
2)模块中include此函数的头文件
......
include/linux/autoconf.h or include/config/auto.conf are missing.
Run 'make oldconfig && make prepare' on kernel src to fix it.
WARNING: Symbol version dump /work/zhaoweixing/linux-2.6.30-kdm201s/Module.symvers
is missing; modules will have no dependencies and modversions.
[root@localhost my-drivers]# ./test
open: No such device or address
驱动写好并编译后的操作:
1)insmod mydriver.ko
2)mknod /dev/chartest c 249 0
3)编写测试程序
$cat test-user.c
#define DEVICE "/dev/chartest"
int main()
{
int fd=0;
fd=open(DEVICE,O_RDWR);
if(fd<0)
perror("open");
close(fd);
return 0;
}
用gcc编译c程序的时候 经常会出现
implicit declaration of function '...' 的warning
偶经过这几天的经验,发现主要有2种情况会产生这种warning
1
2
第二种情况如此:
camif_fsm.c中的函数定义:
void camif_start_c_with_p(camif_cfg_t *cfg, camif_cfg_t *other)
{
// cfg->gc->other = get_camif(CODEC_MINOR);
cfg->gc->other = other;
camif_start_p_with_c(cfg);
}
该函数的声明未包含在camif.h文件中,这样在调用此函数时由于camif_start_p_with_c(cfg)函数的定义在此函数之前,故产生此错误:warning: implicit declaration of function `camif_start_c_with_p'
1、warning: function declaration isn't a prototype
这种错误也是很常见的,主要是对一些函数固定格式的错误使用。比如int function()改称int function(void)
static int xxxx_init(void)记住 不要缺少static ,而static void xxxx_exit(void)