0
我有這個C文件:爲什麼這個Makefile沒有工作?
// test.c
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
而且這個Makefile
OBJS=$(patsubst %.c,%.o,$(wildcard *.c))
EXEC=hello.exe
all: $(EXEC)
$(EXEC): $(OBJS)
.PHONY: all
當我做make
它不會創建我的目標hello.exe
爲什麼?
$ make
cc -c -o hello.o hello.c
它不與任何工作hello.exe
:
$ make hello.exe
make: Nothing to be done for 'hello.exe'.
而且hello.exe
不存在:
$ ls hello.exe
ls: cannot access 'hello.exe': No such file or directory
我使用這個版本的GNU make
$ make --version
GNU Make 4.2.1
Built for x86_64-unknown-cygwin
Copyright (C) 1988-2016 Free Software Foundation, Inc.
編輯
它實際上工作時,我命名我的可執行文件與我的任何文件相同。因此,它的工作原理與:
EXEC=hello
參見:
$ make
cc -c -o hello.o hello.c
cc hello.o -o hello
不過我不明白爲什麼它只能這樣。