導航:首頁 > 源碼編譯 > 模塊編譯

模塊編譯

發布時間:2022-01-12 16:13:21

Ⅰ 驅動編譯進內核和編譯模塊的區別

第一次把自己編譯的驅動模塊載入進開發板,就出現問題,還好沒花費多長時間,下面列舉出現的問題及解決方案1:出現insmod:errorinserting'hello.ko':-1Invalidmoleformat法一(網上的):是因為內核模塊生成的環境與運行的環境不一致,用linux-2.6.27內核源代碼生成的模塊,可能就不能在linux-2.6.32.2內核的linux環境下載入,需要在linux-2.6.27內核的linux環境下載入。a.執行uname-r//查看內核版本b.一般出錯信息被記錄在文件/var/log/messages中,執行下面命令看錯誤信息#cat/var/log/messages|tail若出現類似下面:Jun422:07:54localhostkernel:hello:versionmagic'2.6.35.6-45.fc14.i686.PAE'shouldbe'2.6.35.13-92.fc14.i686.PAE'則把Makefile里的KDIR:=/lib/moles/2.6.35.6-45.fc14.i686.PAE/build1改為KDIR:=/lib/moles/2.6.35.13-92.fc14.i686.PAE/build1//改成自己內核源碼路徑(這里的build1是一個文件鏈接,鏈接到/usr/src/kernels/2.6.35.6-45.fc14.i686.PAE和13-92的)然並卵,我的fedora14/usr/src/kernels下並沒有2.6.35.13-92.fc14.i686.PAE,只有2.6.35.13-92.fc14.i686,雖然不知道兩者有什麼區別,但改成2.6.35.13-92.fc14.i686還是不行,照樣這個問題,還好後來在看教學視頻的到啟發法二:改的還是那個位置KDIR:=/opt/FriendlyARM/linux-2.6.32.2//把這里改成你編譯生成kernel的那個路徑all:$(MAKE)-C$(KDIR)M=$(PWD)molesARCH=armCROSS_COMPILE=arm-linux-//加這句2.[70685.298483]hello:molelicense'unspecified'taintskernel.[70685.298673]方法:在模塊程序中加入:MODULE_LICENSE("GPL");3.rmmod:chdir(2.6.32.2-FriendlyARM):Nosuchfileordirectory錯誤解決方法:lsmod可查看模塊信息即無法刪除對應的模塊。就是必須在/lib/moles下建立錯誤提示的對應的目錄((2.6.32.2)即可。必須創建/lib/moles/2.6.32.2這樣一個空目錄,否則不能卸載ko模塊.#rmmodnls_cp936rmmod:chdir(/lib/moles):Nosuchfileordirectory但是這樣倒是可以卸載nls_cp936,不過會一直有這樣一個提示:rmmod:mole'nls_cp936'notfound初步發現,原來這是編譯kernel時使用makemoles_install生成的一個目錄,但是經測試得知,rmmod:mole'nls_cp936'notfound來自於busybox,並不是來自kernel1).創建/lib/moles/2.6.32.2空目錄2).使用如下源碼生成rmmod命令,就可以沒有任何提示的卸載ko模塊了[luther.gliethttp]#include#include#include#include#include#includeintmain(intargc,char*argv[]){constchar*modname=argv[1];intret=-1;intmaxtry=10;while(maxtry-->0){ret=delete_mole(modname,O_NONBLOCK|O_EXCL);//系統調用sys_delete_moleif(retread_proc=procfile_read;////Our_Proc_File->owner=THIS_MODULE;Our_Proc_File->mode=S_IFREG|S_IRUGO;Our_Proc_File->uid=0;Our_Proc_File->gid=0;Our_Proc_File->size=37;printk("/proc/%screated\n",procfs_name);return0;}voidproc_exit(){remove_proc_entry(procfs_name,NULL);printk(KERN_INFO"/proc/%sremoved\n",procfs_name);}mole_init(proc_init);mole_exit(proc_exit);[html]viewplainifneq($(KERNELRELEASE),)obj-m:=proc.oelseKDIR:=/opt/FriendlyARM/linux-2.6.32.2#KDIR:=/lib/moles/2.6.35.13-92.fc14.i686.PAE/build1PWD:=$(shellpwd)all:$(MAKE)-C$(KDIR)M=$(PWD)molesARCH=armCROSS_COMPILE=arm-linux-clean:rm-f*.ko*.o*.mod.o*.mod.c*.symversendifmake後生成proc.ko,再在開發板上insmodproc.ko即可執行dmesg就可以看到產生的內核信息啦

Ⅱ 如何單獨編譯安卓系統源碼指定模塊

android源碼目錄下的build/envsetup.sh文件,描述編譯的命令

- m: Makes from the top of the tree.

- mm: Builds all of the moles in the current directory.

- mmm: Builds all of the moles in the supplied directories.

要想使用這些命令,首先需要在android源碼根目錄執行. build/envsetup.sh 腳本設置環境

m:編譯所有的模塊

mm:編譯當前目錄下的模塊,當前目錄下要有Android.mk文件

mmm:編譯指定路徑下的模塊,指定路徑下要有Android.mk文件

下面舉個例子說明,假設我要編譯android下的\hardware\libhardware_legacy\power模塊,當前目錄為源碼根目錄,方法如下:

1、. build/envsetup.sh

2、mmm hardware/libhardware_legacy/power/

編譯完後 運行 make snod

會重新將你改過的模塊打入到system.img中

Ⅲ linux內核模塊,怎麼編譯

我來說下吧 本身你這個問題問的有點歧義 不知道你問的是內核編譯 還是模塊編譯 兩個不是一個東西 盡管模塊載入後 也是內核的一部分 看看其他的回答 以為是單純的內核的編譯了 模塊本身在linux下面是可以分為靜態和動態載入的 要是採用靜態載入的話 就是從新編譯內核 和內核的編譯基本是一回事 但是多採用動態載入 這個也簡單點
從你的下面的模版可以看出 你是想寫驅動程序吧 驅動一般作為動態載入的就可以了 寫好你的c文件 格式和上面的差不多 然後GCC編譯 生成.o文件,不要生成可執行文件 ( 如果是玩Embedded 就下載到目標板了 minicom 的使用) 如果是就在linux機器上 直接執行 insmod lsmod rmmod 這些就好了 這里也是簡單的說下了 內核的編譯 寫驅動程序 本身就是個比較難得事情了 要個很長的時間去學習了 慢慢積累 好運

Ⅳ 如何單獨編譯frameworks下的某個模塊

註:mmm和mm命令必須在執行「.build/envsetup.sh」之後才能使用,並且只編譯發生變化的文件。如果要編譯模塊的所有文件,需要-B選項,例如mm -B。

Ⅳ 如何單獨編譯Android源碼中的模塊

1.make 模塊名稱
需要查看Android.mk文件的LOCAL_PACKAGE_NAME變數。
2.mmm命令
用於在源碼根目錄編譯指定模塊,參數為模塊的相對路徑。只能在第一次編譯後使用。比如要編譯Phone部分源碼,需要在終端中執行以下命令:
$mmm packages/apps/phone
3.mm命令
用於在模塊根目錄編譯這個模塊。只能在第一次編譯後使用。例如要編譯Phone部分源碼,需要在終端中執行以下命令:
$cd packages/apps/phone
$mm
註:mmm和mm命令必須在執行「.build/envsetup.sh」之後才能使用,並且只編譯發生變化的文件。如果要編譯模塊的所有文件,需要-B選項,例如mm -B。

Ⅵ 如何編譯一個linux下的驅動模塊

按照《linux設備驅動開發詳解》一書中的步驟實現經典例子"hello,world!"的例子。
具體步驟如下:
=============================================
1.源碼如下:
/*
* hello.c -- the example of printf "hello world!" in the screen of driver program
*/
#include <linux/init.h>
#include <linux/mole.h>
MODULE_LICENSE("Dual BSD/GPL");/* declare the license of the mole ,it is necessary */
static int hello_init(void)
{
printk(KERN_ALERT "Hello World enter!\n");
return 0;
}
static int hello_exit(void)
{
printk(KERN_ALERT "Hello world exit!\n");
}
mole_init(hello_init); /* load the mole */
mole_exit(hello_exit); /* unload the mole */
進入目錄:
[root@Alex_linux /]#cd /work/jiakun_test/moletest
[root@Alex_linux moletest]# vi hello.c
然後拷入上面書上的源碼。
2.編譯代碼:
1>.首先我在2.4內核的虛擬機上進行編譯,編譯過程如下:
[root@Alex_linux moletest]#gcc -D__KERNEL__ -I /usr/src/linux -DMODULE -Wall -O2 -c -o hello.o hello.c
其中-I選項指定內河源碼,也就是內核源碼樹路徑。編譯結果:
hello.c:1:22: net/sock.h: No such file or directory
hello.c: In function `hello_init':
hello.c:6: warning: implicit declaration of function `printk'
hello.c:6: `KERN_ALERT' undeclared (first use in this function)
hello.c:6: (Each undeclared identifier is reported only once
hello.c:6: for each function it appears in.)
hello.c:6: parse error before string constant
hello.c: In function `hello_exit':
hello.c:11: `KERN_ALERT' undeclared (first use in this function)
hello.c:11: parse error before string constant
hello.c: At top level:
hello.c:13: warning: type defaults to `int' in declaration of `mole_init'
hello.c:13: warning: parameter names (without types) in function declaration
hello.c:13: warning: data definition has no type or storage class
hello.c:14: warning: type defaults to `int' in declaration of `mole_exit'
hello.c:14: warning: parameter names (without types) in function declaration
hello.c:14: warning: data definition has no type or storage class
在網上查詢有網友提示沒有引入kernel.h
解決:vi hello.c
在第一行加入:#include <linux/kernel.h>
再次編譯仍然報KERN_ALERT沒有聲明
修改編譯條件-I,再次編譯:
[root@Alex_linux moletest]#gcc -D__KERNEL__ -I /usr/src/linux -DMODULE -Wall -O2 -c -o hello.o hello.c
[root@Alex_linux moletest]#ls
hello.c hello.o Makefile
[root@Alex_linux moletest]#
2>.接著我嘗試在2.6內核的虛擬機上進行編譯
編譯過程如下:
[root@JiaKun moletest]# ls
hello.c makefile
[root@JiaKun moletest]# vi hello.c
[root@JiaKun moletest]# make
make -C /mylinux/kernel/2.4.18-rmk7 M=/home/alex/test/moletest moles
make: *** /mylinux/kernel/2.4.18-rmk7: No such file or directory. Stop.
make: *** [moles] Error 2
[root@JiaKun moletest]# vi makefile
[root@JiaKun moletest]# make
make -C /usr/src/kernels/2.6.18-53.el5-i686 M=/home/alex/test/moletest moles
make[1]: Entering directory `/usr/src/kernels/2.6.18-53.el5-i686'
scripts/Makefile.build:17: /home/alex/test/moletest/Makefile: No such file or directory
make[2]: *** No rule to make target `/home/alex/test/moletest/Makefile'. Stop.
make[1]: *** [_mole_/home/alex/test/moletest] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.18-53.el5-i686'
make: *** [moles] Error 2
[root@JiaKun moletest]# mv makefile Makefile
[root@JiaKun moletest]# make
make -C /usr/src/kernels/2.6.18-53.el5-i686 M=/home/alex/test/moletest moles
make[1]: Entering directory `/usr/src/kernels/2.6.18-53.el5-i686'
CC [M] /home/alex/test/moletest/hello.o
Building moles, stage 2.
MODPOST
CC /home/alex/test/moletest/hello.mod.o
LD [M] /home/alex/test/moletest/hello.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.18-53.el5-i686'
[root@JiaKun moletest]# ls
hello.c hello.ko hello.mod.c hello.mod.o hello.o Makefile Mole.symvers

Ⅶ 易語言模塊的編譯


當子程序編寫完成,在別的窗口裡是無法調用的,除非整體代碼復制過去,那就太麻煩了,所以,需要編譯出一個獨立的EC文件(易語言模塊文件)方便編寫程序時調用,編譯的方法很簡單,執行菜單【程序】-【配置】選項,彈出配置對話框,輸入模塊的信息,單擊確定,然後執行菜單【編譯】-【編譯】或者快捷鍵F7來調出保存文件對話框,選定路徑,輸入文件名,單擊確定按鈕,如無明顯錯誤即可編譯完成。

Ⅷ Linux動態模塊怎樣編譯

編譯模塊的make file 必須是Makefile,不能是makefile. //why?

ifneq ($(KERNELRELEASE),)
obj-m := your.o
mytest-objs := file1.o file2.o file3.o
else
KDIR := /lib/moles/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) M=$(PWD) moles
endif

把your換成你的source name ,然後保存為Mafefile ,make 一次就可以了。

Ⅸ 請教易語言模塊如何編譯成程序

*.e文件是易語言的源代碼文件,該文件中保存了易語言所設計的程序的所有源代碼。無論是*.ec的模塊文件還是*.exe的可執行文件都是通過*.e文件編譯而來的.

如果編譯源代碼文件(也就是*.e的文件)後,生成的是*.ec的文件,那麼說明這份源代碼是一個易語言模塊的源代碼,它只能被編譯為*.ec的易語言模塊文件。

要生成exe的可執行文件,需要在新建易語言程序項目時選擇「Windows窗口程序」類型,該類型的項目可以編譯為exe文件。

另:如何建立「Windows窗口程序」項目?啟動易語言後在彈出的「新建...」窗口中選擇即可。

閱讀全文

與模塊編譯相關的資料

熱點內容
伺服器一直崩應該用什麼指令 瀏覽:916
cm202貼片機編程 瀏覽:723
php構造函數帶參數 瀏覽:175
解壓電波歌曲大全 瀏覽:336
為啥文件夾移到桌面成word了 瀏覽:858
命令符的安全模式是哪個鍵 瀏覽:758
編程中學 瀏覽:956
單片機求助 瀏覽:993
ug加工側面排銑毛坯怎麼編程 瀏覽:271
程序員有關的介紹 瀏覽:736
支付寶使用的什麼伺服器 瀏覽:210
安卓看本地書用什麼軟體好 瀏覽:921
經傳軟體滾動凈利潤指標源碼 瀏覽:522
螢石雲視頻已加密怎麼解除 瀏覽:574
一命令四要求五建議 瀏覽:30
qq文件夾遷移不了 瀏覽:19
液體粘滯系數測定不確定度演算法 瀏覽:332
輕棧源碼 瀏覽:426
把圖片壓縮到500k 瀏覽:35
命令你自己 瀏覽:369