Download ldd_src.rar解压后得ldd_src,进入ldd_src/scull目录,
执行 $ make 后报错如下:
- 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
-
make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
-
scripts/Makefile.build:49: *** CFLAGS was changed in "/home/eric/Downloads/ldd_src/scull/Makefile". Fix it to use EXTRA_CFLAGS. Stop.
-
make[1]: *** [_module_/home/eric/Downloads/ldd_src/scull] Error 2
-
make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
-
make: *** [modules] Error 2
根据出错提示,把Makefile中的CFLAGS 改为 EXTRA_CFLAGS,
再 $ make 报错如下:
- 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
-
make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
-
CC [M] /home/eric/Downloads/ldd_src_test/scull/main.o
-
/home/eric/Downloads/ldd_src_test/scull/main.c:17:26: fatal error: linux/config.h: No such file or directory
-
compilation terminated.
-
make[2]: *** [/home/eric/Downloads/ldd_src_test/scull/main.o] Error 1
-
make[1]: *** [_module_/home/eric/Downloads/ldd_src_test/scull] Error 2
-
make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
-
make: *** [modules] Error 2
这个头文件config.h新版kernel已经没有了,简单的方法就是删除文件中的#include
,但为了具有可移植性,我还是建议用下面这个方法:
- #include <linux/version.h>
- #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18))
-
#include <linux/config.h>
-
#endif
再 $ make 报错如下:
- 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
-
make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
-
CC [M] /home/eric/Downloads/ldd_src_test/scull/main.o
-
/home/eric/Downloads/ldd_src_test/scull/main.c:556:2: error: unknown field ‘ioctl’ specified in initializer
-
/home/eric/Downloads/ldd_src_test/scull/main.c:556:2: warning: initialization from incompatible pointer type
-
/home/eric/Downloads/ldd_src_test/scull/main.c: In function ‘scull_init_module’:
-
/home/eric/Downloads/ldd_src_test/scull/main.c:652:3: error: implicit declaration of function ‘init_MUTEX’
-
make[2]: *** [/home/eric/Downloads/ldd_src_test/scull/main.o] Error 1
-
make[1]: *** [_module_/home/eric/Downloads/ldd_src_test/scull] Error 2
-
make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
-
make: *** [modules] Error 2
这是因为新版本的kernel(linux/fs.h)已对struct file_operations做了改动,先前的ioctl被unlocked_ioctl取代,所以,把所有程序中使用ioctl的地方改成unlocked_ioctl.
再 $ make 报错如下:
- 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
-
make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
-
CC [M] /home/eric/Downloads/ldd_src_test/scull/main.o
-
/home/eric/Downloads/ldd_src_test/scull/main.c:556:2: warning: initialization from incompatible pointer type
-
/home/eric/Downloads/ldd_src_test/scull/main.c: In function ‘scull_init_module’:
-
/home/eric/Downloads/ldd_src_test/scull/main.c:652:3: error: implicit declaration of function ‘init_MUTEX’
-
make[2]: *** [/home/eric/Downloads/ldd_src_test/scull/main.o] Error 1
-
make[1]: *** [_module_/home/eric/Downloads/ldd_src_test/scull] Error 2
-
make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
-
make: *** [modules] Error 2
这是因为 function ‘init_MUTEX’ 没有定义,可以修改一下linux/fs.h
在#include 之后加入:
- #define init_MUTEX(LOCKNAME) sema_init(LOCKNAME,1);
再 $ make 报错如下:
- 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
-
make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
-
CC [M] /home/eric/Downloads/ldd_src_test/scull/main.o
-
/home/eric/Downloads/ldd_src_test/scull/main.c:559:2: warning: initialization from incompatible pointer type
-
CC [M] /home/eric/Downloads/ldd_src_test/scull/pipe.o
-
/home/eric/Downloads/ldd_src_test/scull/pipe.c: In function ‘scull_p_read’:
-
/home/eric/Downloads/ldd_src_test/scull/pipe.c:131:7: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
-
/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
-
/home/eric/Downloads/ldd_src_test/scull/pipe.c:131:3: error: implicit declaration of function ‘signal_pending’
-
/home/eric/Downloads/ldd_src_test/scull/pipe.c:131:3: error: implicit declaration of function ‘schedule’
-
/home/eric/Downloads/ldd_src_test/scull/pipe.c: In function ‘scull_getwritespace’:
-
/home/eric/Downloads/ldd_src_test/scull/pipe.c:168:38: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
-
/home/eric/Downloads/ldd_src_test/scull/pipe.c: In function ‘scull_p_write’:
-
/home/eric/Downloads/ldd_src_test/scull/pipe.c:219:2: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
-
/home/eric/Downloads/ldd_src_test/scull/pipe.c:223:34: error: ‘SIGIO’ undeclared (first use in this function)
-
/home/eric/Downloads/ldd_src_test/scull/pipe.c:223:41: error: ‘POLL_IN’ undeclared (first use in this function)
-
/home/eric/Downloads/ldd_src_test/scull/pipe.c: At top level:
-
/home/eric/Downloads/ldd_src_test/scull/pipe.c:319:2: warning: initialization from incompatible pointer type
-
make[2]: *** [/home/eric/Downloads/ldd_src_test/scull/pipe.o] Error 1
-
make[1]: *** [_module_/home/eric/Downloads/ldd_src_test/scull] Error 2
-
make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
-
make: *** [modules] Error 2
‘TASK_INTERRUPTIBLE’ 未定义,这是因为没有include相应的头文件,它在哪个头文件中定义我们不知道,那么就搜一下include目录:
- grep -rn TASK_INTERRUPTIBLE /usr/src/linux-headers-2.6.38-8-generic/include/
发现位于:
- /usr/src/linux-headers-2.6.38-8-generic/include/linux/sched.h:185:#define TASK_INTERRUPTIBLE 1
在程序pipe.c,access.c头部添加上:
#include
再 $ make 报错如下:
- 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
-
make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
-
CC [M] /home/eric/Downloads/ldd_src_test/scull/access.o
-
/home/eric/Downloads/ldd_src_test/scull/access.c:84:2: warning: initialization from incompatible pointer type
-
/home/eric/Downloads/ldd_src_test/scull/access.c: In function ‘scull_u_open’:
-
/home/eric/Downloads/ldd_src_test/scull/access.c:107:29: error: ‘struct task_struct’ has no member named ‘uid’
-
/home/eric/Downloads/ldd_src_test/scull/access.c:108:29: error: ‘struct task_struct’ has no member named ‘euid’
-
/home/eric/Downloads/ldd_src_test/scull/access.c:115:26: error: ‘struct task_struct’ has no member named ‘uid’
-
/home/eric/Downloads/ldd_src_test/scull/access.c: At top level:
-
/home/eric/Downloads/ldd_src_test/scull/access.c:146:2: warning: initialization from incompatible pointer type
-
/home/eric/Downloads/ldd_src_test/scull/access.c: In function ‘scull_w_available’:
-
/home/eric/Downloads/ldd_src_test/scull/access.c:166:27: error: ‘struct task_struct’ has no member named ‘uid’
-
/home/eric/Downloads/ldd_src_test/scull/access.c:167:27: error: ‘struct task_struct’ has no member named ‘euid’
-
/home/eric/Downloads/ldd_src_test/scull/access.c: In function ‘scull_w_open’:
-
/home/eric/Downloads/ldd_src_test/scull/access.c:185:26: error: ‘struct task_struct’ has no member named ‘uid’
-
/home/eric/Downloads/ldd_src_test/scull/access.c: At top level:
-
/home/eric/Downloads/ldd_src_test/scull/access.c:219:2: warning: initialization from incompatible pointer type
-
/home/eric/Downloads/ldd_src_test/scull/access.c:318:2: warning: initialization from incompatible pointer type
-
/home/eric/Downloads/ldd_src_test/scull/access.c: In function ‘scull_w_available’:
-
/home/eric/Downloads/ldd_src_test/scull/access.c:169:1: warning: control reaches end of non-void function
-
make[2]: *** [/home/eric/Downloads/ldd_src_test/scull/access.o] Error 1
-
make[1]: *** [_module_/home/eric/Downloads/ldd_src_test/scull] Error 2
-
make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
-
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
然后编译,即可通过。
阅读(4140) | 评论(1) | 转发(0) |