2012-03-02 56 views
0

編譯模塊,我創建make文件與外部工具鏈

obj-m += hello.o 

all: 
    make -C /home/developer/Desktop/xukr-20120201-omap3/linux-2.6.37-tn M=/home/developer/Desktop/module_test modules 

clean: 
    make -C /home/developer/Desktop/xukr-20120201-omap3/linux-2.6.37-tn M=/home/developer/Desktop/module_test clean 

然後,我發現了一個簡單的hello程序

#define __KERNEL__   /* We're part of the kernel */ 
#define MODULE    /* Not a permanent part, though. */ 

/* Standard headers for LKMs */ 
#include <linux/modversions.h> 
#include <linux/module.h> 

#include <linux/tty.h>  /* console_print() interface */ 

/* Initialize the LKM */ 
int init_module() 
{ 
    console_print("Hello, world - this is the kernel speaking\n"); 
    /* More normal is printk(), but there's less that can go wrong with 
    console_print(), so let's start simple. 
    */ 

    /* If we return a non zero value, it means that 
    * init_module failed and the LKM can't be loaded 
    */ 
    return 0; 
} 


/* Cleanup - undo whatever init_module did */ 
void cleanup_module() 
{ 
    console_print("Short is the life of an LKM\n"); 
} 

,我試圖在命令行編譯此

make ARCH=arm CROSS_COMPILE=angstrom-linux-gnueabi- 

,我得到這個錯誤

/bin/sh: angstrom-linux-gnueabi-gcc: not found 

有什麼不對呢?我真的很新。

由於提前,

+0

使用'$(MAKE)''不是一個'Makefile' – 2012-03-02 08:41:23

+0

不幸的是同樣的錯誤裏面make'。 – thehilmisu 2012-03-02 08:57:03

+0

在開始使用內核代碼之前,您應該真正獲得用戶級Linux命令行實用程序和應用程序級Linux系統調用的流暢性。 – 2012-03-02 09:15:20

回答

0

你可以使用remake調試和理解你的Makefile。調用它作爲remake -x -d它會給你很多的調試輸出,而其他行爲爲GNU make

正如我所評論的,不要忘記在Makefile內使用$(MAKE)而不是make

關於錯誤:angstrom-linux-gnueabi-gcc: not found您需要在您的系統上安裝適當的交叉編譯器(和交叉鏈接器)工具鏈(或者適當地設置您的環境變量,以便找到它)。

這一切都不會解決你的問題,但會幫助你理解它