我有一個基本的Linux設備驅動程序模塊:Linux設備驅動模塊編譯使用gcc
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
static int __init hello_init(void)
{
printk(KERN_ALERT "Hello, world \n");
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_ALERT "Goodbye, world \n");
}
module_init(hello_init);
module_exit(hello_exit);
我能夠編譯它是通過一個簡單的Makefile文件,它使用OBJ-M傳統方式這個模塊,但我想用命令行gcc編譯這個。這是因爲我可以使用gcc -save-temps標誌來查看中間生成的文件(當Linux內核使用大量預處理器時,這可能特別有用)。
那麼有沒有辦法使用命令行gcc編譯?
編輯附加我用
ifeq ($(KERNELRELEASE),)
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
EXTRA_CFLAGS+= -save-temps
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
.PHONY: modules modules_install clean
else
obj-m := hello.o
endif
在命令行中使用'gcc'成功取決於建立外殼環境適當。這是(部分)make和makefile的作用。如果你真的堅持使用shell,那麼你應該把你的'Makefile'附加到你的問題上以供審查。 – sawdust 2013-03-09 21:28:49