Makefile错误解决⽅法 在makefile中写⼊:
ifneq ($(KERNELRELEASE),)
MODULE_NAME = hellomodule
$(MODULE_NAME)-objs := hello.o
obj-m := $(MODULE_NAME).o
else
KERNEL_DIR = /lib/modules/`uname -r`/build
MODULEDIR := $(shell pwd)
.PHONY: modules
default: modules
modules:
make -C $(KERNEL_DIR) M=$(MODULEDIR) modules
clean distclean:
rm -f *.o *.mod.c .*.*.cmd *.ko
rm -rf .tmp_versions
endif
hechao@ubuntu:/opt/driver$ make
Makefile:16: *** missing separator.  Stop.
makefile的命令⾏,开头必须⽤tab键。将
modules:
make -C $(KERNEL_DIR) M=$(MODULEDIR) modules
clean distclean:
rm -f *.o *.mod.c .*.*.cmd *.ko
rm -rf .tmp_versions
⾥⾯的命令⾏左顶格,再⽤tab键开头。
重新执⾏ make
hechao@ubuntu:/opt/driver$  make
make -C /lib/modules/`uname -r`/build M=/opt/driver modules
make[1]: Entering directory `/usr/src/linux-headers-4.4.0-131-generic'
Makefile:697: Cannot use CONFIG_CC_STACKPROTECTOR_REGULAR: -fstack-protector not supported by compiler mkdir: cannot create directory ‘/opt/driver/.tmp_versions’: Permission denied
CC [M]  /opt/driver/hello.o
makefile phonyAssembler messages:
Fatal error: can't create /opt/driver/.tmp_hello.o: Permission denied
In file included from include/linux/kobject.h:21:0,
from include/linux/module.h:17,
from /opt/driver/hello.c:1:
include/linux/sysfs.h: In function ‘sysfs_get_dirent’:
include/linux/sysfs.h:523:2: warning: pointer targets in passing argument 2 of ‘kernfs_find_and_get’ differ in signedness [-Wpointer-sign]
return kernfs_find_and_get(parent, name);
^
In file included from include/linux/sysfs.h:15:0,
from include/linux/kobject.h:21,
from include/linux/module.h:17,
from /opt/driver/hello.c:1:
include/linux/kernfs.h:433:1: note: expected ‘const char *’ but argument is of type ‘const unsigned char *’ kernfs_find_and_get(struct kernfs_node *kn, const char *name)
^
make[2]: *** [/opt/driver/hello.o] Error 2
make[1]: *** [_module_/opt/driver] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-4.4.0-131-generic'
make: *** [modules] Error 2
执⾏  sudo make 就好了。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。