Makefile .o文件规则问题

时间:2013-11-20 18:40:47

标签: c linux gcc makefile

我正在尝试创建一个简单的makefile来编译我正在linux中开发的示例应用程序(只是为了学习一些东西)但是我遇到了一个奇怪的问题,我不知道它为什么会这样发生..

我有这个makefile:

# 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

这是目录中的文件列表:

  • config.ggo
  • 的main.c
  • debug.h
  • debug.c
  • 生成文件

2 个答案:

答案 0 :(得分:1)

这表示make无法找到您的源文件config.c。您有config.h的规则,但我没有看到要config.c的人。

答案 1 :(得分:0)

我很确定不应该引用$ {PROGRAM_OPT} .c。