Chinaunix首页 | 论坛 | 博客
  • 博客访问: 723816
  • 博文数量: 104
  • 博客积分: 4320
  • 博客等级: 上校
  • 技术积分: 1948
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-30 14:42
文章分类

全部博文(104)

文章存档

2012年(4)

2011年(65)

2010年(35)

分类: LINUX

2011-06-23 14:26:42

Download ldd_src.rar解压后得ldd_src,进入ldd_src/scull目录,
执行 $ make 后报错如下:
  1. make -C /lib/modules/2.6.38-8-generic/build M=/home/eric/Downloads/ldd_src/scull LDDINC=/home/eric/Downloads/ldd_src/scull/../include modules
  2. make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
  3. scripts/Makefile.build:49: *** CFLAGS was changed in "/home/eric/Downloads/ldd_src/scull/Makefile". Fix it to use EXTRA_CFLAGS. Stop.
  4. make[1]: *** [_module_/home/eric/Downloads/ldd_src/scull] Error 2
  5. make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
  6. make: *** [modules] Error 2
根据出错提示,把Makefile中的CFLAGS 改为 EXTRA_CFLAGS,
再 $ make 报错如下:
  1. make -C /lib/modules/2.6.38-8-generic/build M=/home/eric/Downloads/ldd_src_test/scull LDDINC=/home/eric/Downloads/ldd_src_test/scull/../include modules
  2. make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
  3.   CC [M] /home/eric/Downloads/ldd_src_test/scull/main.o
  4. /home/eric/Downloads/ldd_src_test/scull/main.c:17:26: fatal error: linux/config.h: No such file or directory
  5. compilation terminated.
  6. make[2]: *** [/home/eric/Downloads/ldd_src_test/scull/main.o] Error 1
  7. make[1]: *** [_module_/home/eric/Downloads/ldd_src_test/scull] Error 2
  8. make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
  9. make: *** [modules] Error 2
这个头文件config.h新版kernel已经没有了,简单的方法就是删除文件中的#include ,但为了具有可移植性,我还是建议用下面这个方法:
  1. #include <linux/version.h>
  2. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18))
  3. #include <linux/config.h>
  4. #endif

再 $ make 报错如下:
  1. make -C /lib/modules/2.6.38-8-generic/build M=/home/eric/Downloads/ldd_src_test/scull LDDINC=/home/eric/Downloads/ldd_src_test/scull/../include modules
  2. make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
  3.   CC [M] /home/eric/Downloads/ldd_src_test/scull/main.o
  4. /home/eric/Downloads/ldd_src_test/scull/main.c:556:2: error: unknown field ‘ioctl’ specified in initializer
  5. /home/eric/Downloads/ldd_src_test/scull/main.c:556:2: warning: initialization from incompatible pointer type
  6. /home/eric/Downloads/ldd_src_test/scull/main.c: In function ‘scull_init_module’:
  7. /home/eric/Downloads/ldd_src_test/scull/main.c:652:3: error: implicit declaration of function ‘init_MUTEX’
  8. make[2]: *** [/home/eric/Downloads/ldd_src_test/scull/main.o] Error 1
  9. make[1]: *** [_module_/home/eric/Downloads/ldd_src_test/scull] Error 2
  10. make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
  11. make: *** [modules] Error 2
这是因为新版本的kernel(linux/fs.h)已对struct file_operations做了改动,先前的ioctl被unlocked_ioctl取代,所以,把所有程序中使用ioctl的地方改成unlocked_ioctl.
再 $ make 报错如下:
  1. make -C /lib/modules/2.6.38-8-generic/build M=/home/eric/Downloads/ldd_src_test/scull LDDINC=/home/eric/Downloads/ldd_src_test/scull/../include modules
  2. make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
  3.   CC [M] /home/eric/Downloads/ldd_src_test/scull/main.o
  4. /home/eric/Downloads/ldd_src_test/scull/main.c:556:2: warning: initialization from incompatible pointer type
  5. /home/eric/Downloads/ldd_src_test/scull/main.c: In function ‘scull_init_module’:
  6. /home/eric/Downloads/ldd_src_test/scull/main.c:652:3: error: implicit declaration of function ‘init_MUTEX’
  7. make[2]: *** [/home/eric/Downloads/ldd_src_test/scull/main.o] Error 1
  8. make[1]: *** [_module_/home/eric/Downloads/ldd_src_test/scull] Error 2
  9. make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
  10. make: *** [modules] Error 2
这是因为 function ‘init_MUTEX’ 没有定义,可以修改一下linux/fs.h
在#include 之后加入:
  1. #define init_MUTEX(LOCKNAME) sema_init(LOCKNAME,1);
再 $ make 报错如下:
  1. make -C /lib/modules/2.6.38-8-generic/build M=/home/eric/Downloads/ldd_src_test/scull LDDINC=/home/eric/Downloads/ldd_src_test/scull/../include modules
  2. make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
  3.   CC [M] /home/eric/Downloads/ldd_src_test/scull/main.o
  4. /home/eric/Downloads/ldd_src_test/scull/main.c:559:2: warning: initialization from incompatible pointer type
  5.   CC [M] /home/eric/Downloads/ldd_src_test/scull/pipe.o
  6. /home/eric/Downloads/ldd_src_test/scull/pipe.c: In function ‘scull_p_read’:
  7. /home/eric/Downloads/ldd_src_test/scull/pipe.c:131:7: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
  8. /home/eric/Downloads/ldd_src_test/scull/pipe.c:131:7: note: each undeclared identifier is reported only once for each function it appears in
  9. /home/eric/Downloads/ldd_src_test/scull/pipe.c:131:3: error: implicit declaration of function ‘signal_pending’
  10. /home/eric/Downloads/ldd_src_test/scull/pipe.c:131:3: error: implicit declaration of function ‘schedule’
  11. /home/eric/Downloads/ldd_src_test/scull/pipe.c: In function ‘scull_getwritespace’:
  12. /home/eric/Downloads/ldd_src_test/scull/pipe.c:168:38: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
  13. /home/eric/Downloads/ldd_src_test/scull/pipe.c: In function ‘scull_p_write’:
  14. /home/eric/Downloads/ldd_src_test/scull/pipe.c:219:2: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
  15. /home/eric/Downloads/ldd_src_test/scull/pipe.c:223:34: error: ‘SIGIO’ undeclared (first use in this function)
  16. /home/eric/Downloads/ldd_src_test/scull/pipe.c:223:41: error: ‘POLL_IN’ undeclared (first use in this function)
  17. /home/eric/Downloads/ldd_src_test/scull/pipe.c: At top level:
  18. /home/eric/Downloads/ldd_src_test/scull/pipe.c:319:2: warning: initialization from incompatible pointer type
  19. make[2]: *** [/home/eric/Downloads/ldd_src_test/scull/pipe.o] Error 1
  20. make[1]: *** [_module_/home/eric/Downloads/ldd_src_test/scull] Error 2
  21. make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
  22. make: *** [modules] Error 2
‘TASK_INTERRUPTIBLE’ 未定义,这是因为没有include相应的头文件,它在哪个头文件中定义我们不知道,那么就搜一下include目录:
  1. grep -rn TASK_INTERRUPTIBLE /usr/src/linux-headers-2.6.38-8-generic/include/
发现位于:
  1. /usr/src/linux-headers-2.6.38-8-generic/include/linux/sched.h:185:#define TASK_INTERRUPTIBLE    1
在程序pipe.c,access.c头部添加上:
#include


再 $ make 报错如下:
  1. make -C /lib/modules/2.6.38-8-generic/build M=/home/eric/Downloads/ldd_src_test/scull LDDINC=/home/eric/Downloads/ldd_src_test/scull/../include modules
  2. make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
  3.   CC [M] /home/eric/Downloads/ldd_src_test/scull/access.o
  4. /home/eric/Downloads/ldd_src_test/scull/access.c:84:2: warning: initialization from incompatible pointer type
  5. /home/eric/Downloads/ldd_src_test/scull/access.c: In function ‘scull_u_open’:
  6. /home/eric/Downloads/ldd_src_test/scull/access.c:107:29: error: ‘struct task_struct’ has no member named ‘uid’
  7. /home/eric/Downloads/ldd_src_test/scull/access.c:108:29: error: ‘struct task_struct’ has no member named ‘euid’
  8. /home/eric/Downloads/ldd_src_test/scull/access.c:115:26: error: ‘struct task_struct’ has no member named ‘uid’
  9. /home/eric/Downloads/ldd_src_test/scull/access.c: At top level:
  10. /home/eric/Downloads/ldd_src_test/scull/access.c:146:2: warning: initialization from incompatible pointer type
  11. /home/eric/Downloads/ldd_src_test/scull/access.c: In function ‘scull_w_available’:
  12. /home/eric/Downloads/ldd_src_test/scull/access.c:166:27: error: ‘struct task_struct’ has no member named ‘uid’
  13. /home/eric/Downloads/ldd_src_test/scull/access.c:167:27: error: ‘struct task_struct’ has no member named ‘euid’
  14. /home/eric/Downloads/ldd_src_test/scull/access.c: In function ‘scull_w_open’:
  15. /home/eric/Downloads/ldd_src_test/scull/access.c:185:26: error: ‘struct task_struct’ has no member named ‘uid’
  16. /home/eric/Downloads/ldd_src_test/scull/access.c: At top level:
  17. /home/eric/Downloads/ldd_src_test/scull/access.c:219:2: warning: initialization from incompatible pointer type
  18. /home/eric/Downloads/ldd_src_test/scull/access.c:318:2: warning: initialization from incompatible pointer type
  19. /home/eric/Downloads/ldd_src_test/scull/access.c: In function ‘scull_w_available’:
  20. /home/eric/Downloads/ldd_src_test/scull/access.c:169:1: warning: control reaches end of non-void function
  21. make[2]: *** [/home/eric/Downloads/ldd_src_test/scull/access.o] Error 1
  22. make[1]: *** [_module_/home/eric/Downloads/ldd_src_test/scull] Error 2
  23. make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
  24. make: *** [modules] Error 2
说task_struct结构体没有uid,euid成员变量,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

然后编译,即可通过。
阅读(4137) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

scarecrow_wang2014-01-12 13:40:30

多谢大侠!