我正在尝试将所有扩展名为.c的文件编译到一个对象文件夹中,然后创建一个可执行文件。但是,我正在使用的Makefile根本没有注册源文件。相反,它正在继续并调用命令以使用不存在的目标文件创建可执行文件。
这里是Makefile:
CC = clang
SOURCE_DIR = src
OBJECT_DIR = objects
EXECUTABLE = main
SOURCES = $(wildcard $(SOURCE_DIR)/*.c)
OBJECTS = $(patsubst $(SOURCE_DIR)/%.c, $(OBJECT_DIR)/%.o, $(SOURCES))
all: $(OBJECTS)
$(CC) $^ -o $(EXECUTABLE)
clean:
rm objects/*.o main
$(OBJECT_DIR)/%.o: $(SOURCE_DIR)/%.c
$(CC) -c $< -o $@
.PHONY: all $(OBJECTS)
这是输出:
me@hostname:~/parent_dir$ make
clang objects/main.o objects/test.o -o main
clang: error: no such file or directory: 'objects/main.o'
clang: error: no such file or directory: 'objects/test.o'
clang: error: no input files
make: *** [Makefile:11: all] Error 1
这是文件结构:
parent_dir:
\ objects (empty):
\ src:
- main.c
- test.c
- Makefile