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

linux模塊編譯

發布時間:2022-01-17 14:46:09

『壹』 linux編寫內核模塊編譯時找不到頭文件

-I /usr/src/linux-headers-2.6.32-24/include 其中, -I和後面的路徑沒有空格
-I/usr/src/linux-headers-2.6.32-24/include

一般也很少直接用gcc命令, 大部分是用makefile, make -C kernel_path moles

『貳』 在linux中編寫了一個小的內核模塊,怎麼編譯成.ko文件

從網上找一個編譯模塊的Makefile,放到你的模塊的文件夾裡面,然後修改裡面的路徑指定編譯的內核,以及目標名稱。make就可以了。

『叄』 linux編譯模塊的內核版本和現在使用的內核版本不一致的話,怎麼將現在使用的內核版本配成編譯所要的

修改Makefile中的KDIR參數,你現在的Makefile是怎樣寫的?
參考Makefile:
obj-m := moles.o
moles-objs := mymod.o

KDIR=/lib/moles/`uname -r`/build
PWD =$(shell pwd)

default:
make -C $(KDIR) M=$(PWD) moles

clean:
rm -rf *.o .* .cmd *.ko *.mod.c .tmp_version

『肆』 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 一次就可以了。

『伍』 linux怎麼編譯兩個相互依賴的模塊

insmod不過最好是modprobe這個命令會檢測模塊之間的功能依賴關系一同載入。不過需要在/lib/moles裡面有模塊的信息(這個信息怎麼寫怎麼生成我不清楚)。

『陸』 linux內核模塊,怎麼編譯

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

『柒』 linux的編譯內核和編譯內核模塊有什麼區別

當然需要。。。

第一點,就是源碼樹中有相應的頭文件和函數的實現,沒有源碼樹,你哪調用去呢?(PC上編譯的時候內核有導出符號,系統中有頭文件,這樣就可以引用內核給你的介面了,但是只能編譯你PC上版本的內核可載入的模塊)。

第二個,內核模塊中會記錄版本號的部分,需要記錄版本號的原因是不同的內核版本之間,那些介面和調用可能會有比較大的差異,因此必須要保證你的代碼和某個特定的內核對應,這樣編譯出來的模塊就可以(也是只能)在運行這個內核版本的Linux系統中載入,否則一個很簡單的異常就會導致內核崩潰,或者你的代碼根本無法編譯通過(介面名變了)。

我上面說的是編譯模塊的情況,當然如果是把模塊直接編譯到內核當中去的話,那就不用說了,沒有內核源碼,你無法編譯內核。

『捌』 如何編譯一個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

『玖』 linux 模塊編譯,hello.c的內容如下

hello.c:1:22: net/sock.h: No such file or directory

是linux/mole.h 的內容22行的問題吧。

『拾』 linux 模塊編譯顯示沒有頭文件

編寫linux內核模塊,需要自己編寫Makefile,同時在Makefile裡面制定自己的內核路徑,這樣才能處理提示沒有頭文件錯誤。

編譯命令:

exportPATH=$PATH:#編譯工具鏈路徑
exportARCH=#CPU類別(例如arm)
exportCROSS_COMPILE=arm-none-linux-gnueabi-#(編譯工具xx-gcc的前綴xx)
make-C#編譯好的內核模塊運行的Linuxkernel內核源代碼目錄樹M=$`pwd`moles

Linux模塊編譯例子:

exportPATH=$PATH:/usr/local/arm/4.2.2-eabi/usr/bin
#forSamsungs5pc100
exportARCH=arm
exportCROSS_COMPILE=arm-none-linux-gnueabi-
make-C/home/wenxy/src/s5pc100/linux-2.6.35.5M=$`pwd`moles
閱讀全文

與linux模塊編譯相關的資料

熱點內容
工作三年的大專程序員 瀏覽:728
java畢業設計文獻 瀏覽:143
籌碼集中度指標源碼 瀏覽:482
listsortjava 瀏覽:186
plc閃光電路編程實例 瀏覽:299
socket編程試題 瀏覽:206
華為的伺服器怎麼設置從光碟機啟動 瀏覽:871
程序員真的累嗎 瀏覽:328
學信網app為什麼刷臉不了 瀏覽:874
天蠍vs程序員 瀏覽:996
單片機下載口叫什麼 瀏覽:190
程序員的道 瀏覽:926
雲伺服器不實名違法嗎 瀏覽:558
怎樣查看文件夾圖片是否重復 瀏覽:995
文件怎麼導成pdf文件 瀏覽:808
打開sql表的命令 瀏覽:103
安卓手機如何面部支付 瀏覽:38
天元數學app為什麼登錄不上去 瀏覽:825
明日之後為什麼有些伺服器是四個字 瀏覽:104
安卓系統l1是什麼意思 瀏覽:26