编译环境Ubuntu12.04 linux-3.2
- make -C /lib/modules/3.2.0/build M=/home/wrk/works/drivers/ldd3/examples/scull LDDINC=/home/wrk/works/drivers/ldd3/examples/scull/../include modules
- make[1]: Entering directory `/home/wrk/works/drivers/linux-kernel/linux-3.2'
- scripts/Makefile.build:49: *** CFLAGS was changed in "/home/wrk/works/drivers/ldd3/examples/scull/Makefile". Fix it to use ccflags-y. Stop.
如提示所示:在Makefile中用ccflags-y替换CFLAGS
- /home/wrk/works/drivers/ldd3/examples/scull/main.c:17:26: fatal error: linux/config.h: No such file or directory
- compilation terminated.
- make[2]: *** [/home/wrk/works/drivers/ldd3/examples/scull/main.o] Error 1
直接删掉config.h这行
- /home/wrk/works/drivers/ldd3/examples/scull/main.c:556:2: error: unknown field ‘ioctl’ specified in initializer
- /home/wrk/works/drivers/ldd3/examples/scull/main.c:556:2: warning: initialization from incompatible pointer type [enabled by default]
用unlocded_ioctl替换ioctl
- /home/wrk/works/drivers/ldd3/examples/scull/main.c:652:3: error: implicit declaration of function ‘init_MUTEX’ [-Werror=implicit-function-declaration]
- cc1: some warnings being treated as errors
解决方案:在相应文件开始添加
- #include <linux/semaphore.h>
- #define init_MUTEX(a) sema_init(a,1)
- #define init_MUTEX_LOCKED(a) sema_init(a,0)
- /home/wrk/works/drivers/ldd3/examples/scull/pipe.c: In function ‘scull_p_read’:
- /home/wrk/works/drivers/ldd3/examples/scull/pipe.c:131:7: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
- /home/wrk/works/drivers/ldd3/examples/scull/pipe.c:131:7: note: each undeclared identifier is reported only once for each function it appears in
- /home/wrk/works/drivers/ldd3/examples/scull/pipe.c:131:3: error: implicit declaration of function ‘signal_pending’ [-Werror=implicit-function-declaration]
- /home/wrk/works/drivers/ldd3/examples/scull/pipe.c:131:3: error: implicit declaration of function ‘schedule’ [-Werror=implicit-function-declaration]
在pipe.c和access.c中添加“#include <linux/sched.h>"
- /home/wrk/works/drivers/ldd3/examples/scull/access.c:101:34: error: ‘SPIN_LOCK_UNLOCKED’ undeclared here (not in a function)
原因:新版本内核中,SPIN_LOCK_UNLOCKED被移除
建议:使用DEFINE_SPINLOCK(lock)宏来替代
- /*static spinlock_t scull_w_lock = SPIN_LOCK_UNLOCKED;*改成下面到方式/
- static DEFINE_SPINLOCK(scull_w_lock);
- /home/wrk/works/drivers/ldd3/examples/scull/access.c:111:29: error: ‘struct task_struct’ has no member named ‘uid’
- /home/wrk/works/drivers/ldd3/examples/scull/access.c:112:29: error: ‘struct task_struct’ has no member named ‘euid’
- /home/wrk/works/drivers/ldd3/examples/scull/access.c:119:26: error: ‘struct task_struct’ has no member named ‘uid’
struct task_struct定义在include/linux/sched.h中,原来task_struct结构体定义有所改动,将uid和euid等挪到 cred中,见include/linux/sched.h和include/linux/cred.h。
因此只需要将报error的代码做如下修改
current->uid 修改为 current->cred->uid
current->euid 修改为 current->cred->euid
然后make,就大功告成了
阅读(2619) | 评论(0) | 转发(0) |