LDD3在Ubuntu下編譯 scull例子時遇到的一些問題

來源:互聯網
上載者:User

   

原文:http://blog.csdn.net/lxmky/archive /2010/06/17/5675706.aspx

在Linux下的驅動開發時,編寫碰到一個問題,就是在Ubuntu 下不能編譯,經過網上的搜尋後,找到如下一篇部落格,非常不錯,如下: 編譯LDD3-scull


1、提示scripts/Makefile.build:46:*** CFLAGS was changed in "/home/chenfang/scull/Makefile",Fix it use EXTRA_CFLAGS.Stop.:

由於LDD3使用的是2.6.10核心,很多東西已經發生了變化,這裡提示我們修改Makefile中的CFLAGS,用EXTRA_CFLAGS 代替,照它說的做就可以。

2、提示找不到檔案linux/config.h: 在2.6.19開始的核心中刪除了config.h檔案,因此只要在mian.c中注釋掉#include即可。

3、提示access.c中存在:dereferencing pointer to incomplete type 錯誤: 在 源碼中發現只能是current存在錯誤,current應該是一個task_struct類型的全域變數,尋找task_struct存在於 linux/sched.h中,因此在access.c中加入#include,重新make即可。


順便看下current這個全域變數是在哪裡定義的: 在source ininsight中尋找得到的current類似於以下的定義: static inline struct task_struct *get_current(void) __attribute_const__; static inline struct task_struct *get_current(void) { return current_thread_info()->task; } #define current (get_current()) 可 見,current其實是一個“偽全域變數”,是函數get_current()的宏定義。


當access.c中使用current->uid時, 就調用了get_current()函數,從而返回task_struct結構的task,因此current->uid就相當於 task->uid。 之前在Ubuntu裡編譯scull時有錯誤,還好有網友提供瞭解決辦法,即刪除config.h檔案和增加#include 兩個標頭檔:capability.h和sched.h 最近將Ubuntu升級到9.10版本後,重建了2.6.31版本的核心樹,沒想到編譯scull模組時出現新的

/home/dengwei/eclipse_workspace/scull/access.c:108: error: ‘struct task_struct’ has no member named ‘uid’

/home/dengwei/eclipse_workspace/scull/access.c:109: error: ‘struct task_struct’ has no member named ‘euid’

/home/dengwei/eclipse_workspace/scull/access.c:116: error: ‘struct task_struct’ has no member named ‘uid’ /home/dengwei/eclipse_workspace/scull/access.c: In function ‘scull_w_available’:

/home/dengwei/eclipse_workspace/scull/access.c:167: error: ‘struct task_struct’ has no member named ‘uid’

/home/dengwei/eclipse_workspace/scull/access.c:168: error: ‘struct task_struct’ has no member named ‘euid’

/home/dengwei/eclipse_workspace/scull/access.c: In function ‘scull_w_open’:


/home/dengwei/eclipse_workspace/scull/access.c:186: 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 success


結果: root@dw:/home/dengwei/eclipse_workspace/scull# ls access.c main.o Module.symvers scull.init scull.mod.o access.o Makefile pipe.c scull.ko scull.o _desktop.ini Module.markers pipe.o scull_load scull_unload main.c modules.order scull.h scull.mod.c root@dw:/home/dengwei/eclipse_workspace/scull# insmod scull.ko 按照上面提示,就可以順利編譯成ko檔案,其中include/linux在我的Linux中絕對路徑名是 /usr/src/linux-headers-2.6.32-21/include/linux

 

 

與硬體通訊

#include <linux/ioctl.h> /* needed for the _IOW etc stuff used later */
#include <mach/hardware.h>
#include <asm/io.h>
#include <linux/ioport.h>
#include <mach/regs-gpio.h>
#include <mach/regs-gpioj.h>
標頭檔

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.