我正在尝试制作一个简单的 makefile 来编译我在 Linux 中开发的示例应用程序(只是为了学习一些东西)但是我遇到了一个奇怪的问题,我不明白为什么会这样发生..
我有这个生成文件:
# Easily adaptable makefile for Advanced Programming
# Compiler flags
CFLAGS=-Wall -W -g -Wmissing-prototypes
# Indentation flags
IFLAGS=-br -brs -npsl -ce -cli4
# Name of the executable
PROGRAM=ex2
# Prefix for the gengetopt file (if gengetopt is used)
PROGRAM_OPT=config
# Object files required to build the executable
PROGRAM_OBJS=debug.o ${PROGRAM_OPT}.o
# Clean and all are not files
.PHONY: clean all docs indent
all: ${PROGRAM}
# compile with debug
debugon: CFLAGS += -D SHOW_DEBUG -g
debugon: ${PROGRAM}
${PROGRAM}: ${PROGRAM_OBJS}
${CC} -o $@ ${PROGRAM_OBJS}
# Generates command line arguments code from gengetopt configuration file
${PROGRAM_OPT}.h: ${PROGRAM_OPT}.ggo
gengetopt < ${PROGRAM_OPT}.ggo --file-name=${PROGRAM_OPT}
# Dependencies
${PROGRAM_OPT}.o: ${PROGRAM_OPT}.c ${PROGRAM_OPT}.h
debug.o: debug.c debug.h
main.o: debug.h ${PROGRAM_OPT}.h
#how to create an object file (.o) from C file (.c)
.c.o:
${CC} ${CFLAGS} -c $<
clean:
rm -f *.o core.* *~ ${PROGRAM} *.bak ${PROGRAM_OPT}.h ${PROGRAM_OPT}.c
indent:
indent ${IFLAGS} *.c *.h
输入 make 后,我收到一条错误消息:
make: *** No rule to make target `config.c', needed by `config.o'. Stop.
我可能遗漏了一些东西,但如果我没记错的话,该行明确存在于 PROGRAM_OPT 下
这是目录中的文件列表:
- 配置.ggo
- 主程序
- 调试.h
- 调试.c
- 生成文件
最佳答案
这表示 make
无法找到您的源文件 config.c
。你有一个规则来制作 config.h
,但我没有看到一个规则来制作 config.c
。
关于c - Makefile .o 文件规则问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20104239/