我有一个基本的Linux设备驱动程序模块:Linux设备驱动模块编译使用gcc
#include
#include
#include
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
+0
在命令行中使用'gcc'成功取决于建立外壳环境适当。这是(部分)make和makefile的作用。如果你真的坚持使用shell,那么你应该把你的'Makefile'附加到你的问题上以供审查。 –
2013-03-09 21:28:49