ldd源码编译出现的问题

1、Fix it to use EXTRA_CFLAGS.  Stop

1). # make KBUILD_NOPEDANTIC=1
2). Relace all CFLAGS with EXTRA_CFLAGS in the Makefile

 

==================================================

将makefile中的 CFLAGS 替换成 EXTRA_CFLAGS就可以了。

原因是在2.6的内核的版本中所有的 EXTRA_ 变量只在所定义的Kbuild Makefile中起作用。

EXTRA_ 变量可以在Kbuild Makefile中所有命令中使用。   

$(EXTRA_CFLAGS) 是用 $(CC) 编译C源文件时的选项。   

例子:         

# drivers/sound/emu10kl/Makefile         

EXTRA_CFLAGS += -I$(obj)         

ifdef DEBUG              

EXTRA_CFLAGS += -DEMU10KL_DEBUG         

endif   

该变量是必须的,因为顶层Makefile拥有变量 $(CFLAGS) 并用来作为整个源代码树的编译选项。 

 

===================================================

For the "Linux device driver III", the example of "chapter 4":
Delete the <linux/config.h>
Add the <linux/sched.h>

Ok, now change into its derectory and complile it like this:

[root@localhost scull]# make
make -C /lib/modules/2.6.24.2-2lp/build M=/root/Desktop/examples/scull LDDINC=/root/Desktop/examples/scull/../include modules
make[1]: Entering directory `/usr/src/kernels/2.6.24.2-2lp-i686'
scripts/Makefile.build:46: *** CFLAGS was changed in "/root/Desktop/examples/scull/Makefile". Fix it to use EXTRA_CFLAGS. Stop.
make[1]: *** [_module_/root/Desktop/examples/scull] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.24.2-2lp-i686'
make: *** [modules] Error 2

There are two kind of method to solve this problem:

(1)Rplace all CFLAGS with EXTRA_CFLAGS in the Makefile.

(2)Using the KBUILD_NOPEDANTIC arg
[root@localhost scull]# make KBUILD_NOPEDANTIC=1
make -C /lib/modules/2.6.24.2-2lp/build M=/root/Desktop/examples/scull LDDINC=/root/Desktop/examples/scull/../include modules
make[1]: Entering directory `/usr/src/kernels/2.6.24.2-2lp-i686'
CC [M] /root/Desktop/examples/scull/main.o
CC [M] /root/Desktop/examples/scull/pipe.o
CC [M] /root/Desktop/examples/scull/access.o
LD [M] /root/Desktop/examples/scull/scull.o
Building modules, stage 2.
MODPOST 1 modules
CC      /root/Desktop/examples/scull/scull.mod.o
LD [M] /root/Desktop/examples/scull/scull.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.24.2-2lp-i686'

 2、linux/config.h: No such file or directory 

$ make
make -C /lib/modules/2.6.18-1.2798a_FC6/build SUBDIRS=/home/njc/stuff/linux-labjack/driver/linux-2.6 modules
make[1]: Entering directory `/usr/src/redhat/BUILD/kernel-2.6.181.2798a_FC6'
CC [M] /home/njc/stuff/linux-labjack/driver/linux-2.6/labjack.o
/home/njc/stuff/linux-labjack/driver/linux-2.6/labjack.c:43:26: error: linux/config.h: No such file or directory
make[2]: *** [/home/njc/stuff/linux-labjack/driver/linux-2.6/labjack.o] Error 1
make[1]: *** [_module_/home/njc/stuff/linux-labjack/driver/linux-2.6] Error 2
make[1]: Leaving directory `/usr/src/redhat/BUILD/kernel-2.6.181.2798a_FC6'
make: *** [default] Error 2
 

A solution, which I based from a discussion in this blog http://www.phoronix.com/redblog/?p=blog&i=NTUwMA, would be to copy a config.h header file to your /lib/modules/KERNEL-VERSION/build/include/linux directory. If you have a previous kernel build on your computer you can copy the file from your /lib/modules/OLD-KERNEL-VERSION/build/include/linux directory. Alternatively you can just copy the code below into a self made  config.h file

CODE
#ifndef _LINUX_CONFIG_H
#define _LINUX_CONFIG_H

#include <linux/autoconf.h>

#endif

3.dereferencing pointer to incomplete type

错误:
  1. /home/lingd/arm2410s/ldd3/chapter4/scumm/scumm.c: In function 'scumm_open':
  2. /home/lingd/arm2410s/ldd3/chapter4/scumm/scumm.c:54: error: dereferencing pointer to incomplete type
  3. /home/lingd/arm2410s/ldd3/chapter4/scumm/scumm.c:54: error: dereferencing pointer to incomplete type
  4. /home/lingd/arm2410s/ldd3/chapter4/scumm/scumm.c: In function 'scumm_release':
  5. /home/lingd/arm2410s/ldd3/chapter4/scumm/scumm.c:96: error: dereferencing pointer to incomplete type
  6. /home/lingd/arm2410s/ldd3/chapter4/scumm/scumm.c:96: error: dereferencing pointer to incomplete type
  7. /home/lingd/arm2410s/ldd3/chapter4/scumm/scumm.c: In function 'scumm_read':
  8. /home/lingd/arm2410s/ldd3/chapter4/scumm/scumm.c:140: error: dereferencing pointer to incomplete type
  9. /home/lingd/arm2410s/ldd3/chapter4/scumm/scumm.c:140: error: dereferencing pointer to incomplete type
  10. /home/lingd/arm2410s/ldd3/chapter4/scumm/scumm.c: In function 'scumm_write':
  11. /home/lingd/arm2410s/ldd3/chapter4/scumm/scumm.c:210: error: dereferencing pointer to incomplete type
  12. /home/lingd/arm2410s/ldd3/chapter4/scumm/scumm.c:210: error: dereferencing pointer to incomplete type
 
出错语句:
  1. printk(KERN_DEBUG "\"%s(pid %d)\" open scumm device!\n", current->comm, current->pid);
宏current定义在arch/arm/include/asm/current.h中,
  1. static inline struct task_struct *get_current(void)
  2. {
  3.     return current_thread_info()->task;
  4. }
  5. #define current (get_current())
出错原因:
编译器不知道task_struct的具体定义,因此,无法解引用current,无法获知其成员comm、pid的类型,才报“dereferencing pointer to incomplete type”
task_struct定义在<linux/sched.h>中。在源文件头,加上#include <linux/sched.h>,即可解决问题!
“dereferencing pointer to incomplete type”错误,大多也是因为不知道struct/class/emun/union等的定义而引起的
 

4、'struct task_struct' has no member named 'uid'

/home/jqzeng/workSpace/ldd3/ldd3-samples-1.0.0/scull/access.c:107:29: error: 'struct task_struct' has no member named 'uid'
/home/jqzeng/workSpace/ldd3/ldd3-samples-1.0.0/scull/access.c:108:29: error: 'struct task_struct' has no member named 'euid'
原因:新的struct task_struct 定义有变化,uid和euid在cred结构体中。
解决办法:加头文件cred.h,将 current->uid改为current->cred->uid,current->euid改为current->cred->euid
#include <linux/cred.h>
108         if (scull_u_count &&
109                         (scull_u_owner != current->cred->uid) &&  /* allow user */
110                         (scull_u_owner != current->cred->euid) && /* allow whoever did su */
...
117                 scull_u_owner = current->cred->uid; /* grab it */

 

转载于:https://www.cnblogs.com/zhangwuyin/p/4316241.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值