LDD3中scull在新内核上编译中的各种error处理
2016-06-15 21:46
507 查看
LDD3中的第一个例程就是scull,但是在新内核上编译的过程那叫一个坎坷。。。
在此做出总结,希望可以帮到同路人。。。
一、错误:
error: linux/config.h: No such file or directory
解决:
从linux-2.6.20起,config.h就已经被移除了.
在main.c中,
将
改为:
二、错误:
/ldd3_examples/scull/main.c:32:46: fatal error: asm/system.h: No such file or directory
解决:
在main.c中,
将
改为:
在目录:/usr/src/linux-headers-3.11.0-15/include下没有asm,只有asm-generic,执行
三、错误:
error: implicit declaration of function ‘init_MUTEX’ [-Werror=implicit-function-declaration]
解决:
在新版本的linux内核中,init_mutex已经被废除了,新版本使用sema_init函数。需要在main.c中包含头文件
将
改为:
四、错误:
解决:
原因是:在2.6.36内核上file_operations发生了重大的改变:
原先的
int (ioctl)(struct inode, struct file*, unsigned int, unsigned long);
被改为了
long (unlocked_ioctl) (struct file , unsigned int, unsigned long);
long (compat_ioctl) (struct file , unsigned int, unsigned long);
因而在实际驱动中,我们需要将原先的写的ioctl函数头给改成下面的unlocked_ioctl,在file_operations结构体的填充中也是一样。
五、错误:
/home/jassion/work/book/ldd3_examples/scull/pipe.c: In function ‘scull_p_read’:
/home/jassion/work/book/ldd3_examples/scull/pipe.c:131:7: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/jassion/work/book/ldd3_examples/scull/pipe.c:131:7: note: each undeclared identifier is reported only once for each function it appears in
/home/jassion/work/book/ldd3_examples/scull/pipe.c:131:3: error: implicit declaration of function ‘signal_pending’ [-Werror=implicit-function-declaration]
/home/jassion/work/book/ldd3_examples/scull/pipe.c:131:3: error: implicit declaration of function ‘schedule’ [-Werror=implicit-function-declaration]
/home/jassion/work/book/ldd3_examples/scull/pipe.c: In function ‘scull_getwritespace’:
/home/jassion/work/book/ldd3_examples/scull/pipe.c:168:38: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/jassion/work/book/ldd3_examples/scull/pipe.c: In function ‘scull_p_write’:
/home/jassion/work/book/ldd3_examples/scull/pipe.c:219:2: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/jassion/work/book/ldd3_examples/scull/pipe.c:223:34: error: ‘SIGIO’ undeclared (first use in this function)
/home/jassion/work/book/ldd3_examples/scull/pipe.c:223:41: error: ‘POLL_IN’ undeclared (first use in this function)
解决:
头文件变动原因,在pipe.c中添加
六、错误:
/home/jassion/work/book/ldd3_examples/scull/pipe.c:321:2:error: unknown field ‘ioctl’ specified in initializer
解决:
在pipe.c中,
将
改为
七、错误:
/home/jassion/work/book/ldd3_examples/scull/pipe.c: In function ‘scull_p_init’:
/home/jassion/work/book/ldd3_examples/scull/pipe.c:367:3: error: implicit declaration of function ‘init_MUTEX’ [-Werror=implicit-function-declaration]
解决:
在pipe.c中,
将
改为:
八、错误:
access.c中的一系列错误
1、/home/jassion/work/book/ldd3_examples/scull/access.c:98:34: error: ‘SPIN_LOCK_UNLOCKED’ undeclared here (not in a function)
解决:原因,SPIN_LOCK_UNLOCKED在新内核中被弃用
在access.c中添加头文件:
修改定义
为:
2、/home/jassion/work/book/ldd3_examples/scull/access.c:179:3: error: implicit declaration of function ‘signal_pending’ [-Werror=implicit-function-declaration]
/home/jassion/work/book/ldd3_examples/scull/access.c:179:3: error: implicit declaration of function ‘schedule’ [-Werror=implicit-function-declaration]。。。。。。。
解决:
在access.c中添加头文件:
3、/home/jassion/work/book/ldd3_examples/scull/access.c: In function ‘scull_u_open’:
/home/jassion/work/book/ldd3_examples/scull/access.c:108:29: error: ‘struct task_struct’ has no member named ‘uid’
/home/jassion/work/book/ldd3_examples/scull/access.c:109:29: error: ‘struct task_struct’ has no member named ‘euid’
/home/jassion/work/book/ldd3_examples/scull/access.c:116:26: error: ‘struct task_struct’ has no member named ‘uid’
。。。。。。
解决:原因:新的struct task_struct 定义有变化,uid和euid在cred结构体中。
办法:加头文件
将 current->uid改为current->cred->uid,
current->euid改为current->cred->euid
其他的问题,参考上面的方法进行处理即可。
编译成功之后的截图:
在此做出总结,希望可以帮到同路人。。。
一、错误:
error: linux/config.h: No such file or directory
解决:
从linux-2.6.20起,config.h就已经被移除了.
在main.c中,
将
#include <linux/config.h>
改为:
#include <linux/version.h> #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)) #include <linux/config.h> #endif
二、错误:
/ldd3_examples/scull/main.c:32:46: fatal error: asm/system.h: No such file or directory
解决:
在main.c中,
将
#include <asm/system.h> /* cli(), *_flags */
改为:
#if LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0) #include <asm/switch_to.h> #else #include <asm/system.h> /* cli(), *_flags */ #endif
在目录:/usr/src/linux-headers-3.11.0-15/include下没有asm,只有asm-generic,执行
ln -s asm-generic asm可以解决。
三、错误:
error: implicit declaration of function ‘init_MUTEX’ [-Werror=implicit-function-declaration]
解决:
在新版本的linux内核中,init_mutex已经被废除了,新版本使用sema_init函数。需要在main.c中包含头文件
#include<linux/semaphore.h>
将
init_MUTEX(&scull_devices[i].sem);
改为:
sema_init(&scull_devices[i].sem,1);
四、错误:
error: unknown field ‘ioctl’ specified in initializer
解决:
原因是:在2.6.36内核上file_operations发生了重大的改变:
原先的
int (ioctl)(struct inode, struct file*, unsigned int, unsigned long);
被改为了
long (unlocked_ioctl) (struct file , unsigned int, unsigned long);
long (compat_ioctl) (struct file , unsigned int, unsigned long);
因而在实际驱动中,我们需要将原先的写的ioctl函数头给改成下面的unlocked_ioctl,在file_operations结构体的填充中也是一样。
五、错误:
/home/jassion/work/book/ldd3_examples/scull/pipe.c: In function ‘scull_p_read’:
/home/jassion/work/book/ldd3_examples/scull/pipe.c:131:7: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/jassion/work/book/ldd3_examples/scull/pipe.c:131:7: note: each undeclared identifier is reported only once for each function it appears in
/home/jassion/work/book/ldd3_examples/scull/pipe.c:131:3: error: implicit declaration of function ‘signal_pending’ [-Werror=implicit-function-declaration]
/home/jassion/work/book/ldd3_examples/scull/pipe.c:131:3: error: implicit declaration of function ‘schedule’ [-Werror=implicit-function-declaration]
/home/jassion/work/book/ldd3_examples/scull/pipe.c: In function ‘scull_getwritespace’:
/home/jassion/work/book/ldd3_examples/scull/pipe.c:168:38: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/jassion/work/book/ldd3_examples/scull/pipe.c: In function ‘scull_p_write’:
/home/jassion/work/book/ldd3_examples/scull/pipe.c:219:2: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/jassion/work/book/ldd3_examples/scull/pipe.c:223:34: error: ‘SIGIO’ undeclared (first use in this function)
/home/jassion/work/book/ldd3_examples/scull/pipe.c:223:41: error: ‘POLL_IN’ undeclared (first use in this function)
解决:
头文件变动原因,在pipe.c中添加
#include <linux/sched.h>
六、错误:
/home/jassion/work/book/ldd3_examples/scull/pipe.c:321:2:error: unknown field ‘ioctl’ specified in initializer
解决:
在pipe.c中,
将
.ioctl = scull_ioctl,
改为
.unlocked_ioctl = scull_ioctl,
七、错误:
/home/jassion/work/book/ldd3_examples/scull/pipe.c: In function ‘scull_p_init’:
/home/jassion/work/book/ldd3_examples/scull/pipe.c:367:3: error: implicit declaration of function ‘init_MUTEX’ [-Werror=implicit-function-declaration]
解决:
在pipe.c中,
将
init_MUTEX(&scull_p_devices[i].sem);
改为:
sema_init(&scull_p_devices[i].sem,1);
八、错误:
access.c中的一系列错误
1、/home/jassion/work/book/ldd3_examples/scull/access.c:98:34: error: ‘SPIN_LOCK_UNLOCKED’ undeclared here (not in a function)
解决:原因,SPIN_LOCK_UNLOCKED在新内核中被弃用
在access.c中添加头文件:
#include <linux/spinlock_types.h>
修改定义
static spinlock_t scull_u_lock = SPIN_LOCK_UNLOCKED;
为:
static DEFINE_SPINLOCK(scull_u_lock);
2、/home/jassion/work/book/ldd3_examples/scull/access.c:179:3: error: implicit declaration of function ‘signal_pending’ [-Werror=implicit-function-declaration]
/home/jassion/work/book/ldd3_examples/scull/access.c:179:3: error: implicit declaration of function ‘schedule’ [-Werror=implicit-function-declaration]。。。。。。。
解决:
在access.c中添加头文件:
#include <linux/sched.h>
3、/home/jassion/work/book/ldd3_examples/scull/access.c: In function ‘scull_u_open’:
/home/jassion/work/book/ldd3_examples/scull/access.c:108:29: error: ‘struct task_struct’ has no member named ‘uid’
/home/jassion/work/book/ldd3_examples/scull/access.c:109:29: error: ‘struct task_struct’ has no member named ‘euid’
/home/jassion/work/book/ldd3_examples/scull/access.c:116:26: error: ‘struct task_struct’ has no member named ‘uid’
。。。。。。
解决:原因:新的struct task_struct 定义有变化,uid和euid在cred结构体中。
办法:加头文件
#include <linux/cred.h>,
将 current->uid改为current->cred->uid,
current->euid改为current->cred->euid
其他的问题,参考上面的方法进行处理即可。
编译成功之后的截图:
相关文章推荐
- Linux 自检和 SystemTap
- LKRG:用于运行时完整性检查的可加载内核模块
- 一张图看尽 Linux 内核运行原理
- Greg Kroah-Hartman 解释内核社区是如何使 Linux 安全的
- Aut2Exe编译au3脚本为可执行文件
- CentOS 6.3下编译安装Ruby 2.0笔记
- 把Lua编译进nginx步骤方法
- Lua中编译执行代码相关的函数详解
- Chrome Visual Studio 2005下的编译过程
- Windows下使用Cygwin编译MySQL客户端
- android的编译和运行过程深入分析
- Linux内核链表实现过程
- c#中xml文档注释编译dll引用到其它项目示例
- Lua cjson模块编译笔记及错误解决方法
- SQLSERVER编译与重编译发生场景及重用的利弊介绍
- 浅析使用Turck-mmcache编译来加速、优化PHP代码
- 如何编译libfreetype方法详解
- 深入理解C语言中编译相关的常见错误
- 在VS2008中编译MYSQL5.1.48的方法
- Nginx编译参数大全 configure参数中文详解