0

For my assignment, we are supposed to compile cpp2html.c to produce cpp2html.o. We are to do the same thing with lex.yy.c. lex.yy.c is created by the command flex cppscanner.l. Lastly, we're supposed to link the .o files together to produce an executable program named cpp2html. My makefile is supposed to use gcc instead of g++, which I believe I am doing correctly. I've tried to get this specific makefile to work for this program for a few hours now, as the one for the g++ portion worked fine. When I submit this makefile, I'm told that "Your makefile does too much work when only cpp2html.c has been changed." I tried looking up this error, and was only able to find someone who had the error on the g++ portion; I tried adapting it, but it didn't work. I've tried changing the format of the makefile, I've tried altering the codes, but I just don't know what I'm doing wrong.

How can I alter my makefile to do what it needs to, without making it do "too much work"?

My makefile is as follows.

cpp2html: cpp2html.o lex.yy.o
    gcc -g -DDEBUG cpp2html.o lex.yy.o
    mv a.out cpp2html
cpp2html.o: cpp2html.c
    gcc -g -DDEBUG -c cpp2html.c
    flex cppscanner.l
lex.yy.o: lex.yy.c
    gcc -g -c lex.yy.c

EDIT:

cpp2html: cpp2html.o lex.yy.o
    gcc -g cpp2html.o lex.yy.o
    gcc -g -DDEBUG cpp2html.o lex.yy.o -o cpp2html
cpp2html.o: cpp2html.c
    gcc -g -c cpp2html.c
lex.yy.c: cppscanner.l
    flex cppscanner.l
lex.yy.o: lex.yy.c
    gcc -g -c lex.yy.c
4

1 回答 1

0

这个makefile应该解决这个问题,

cpp2html: cpp2html.o lex.yy.o
    gcc -g -DDEBUG cpp2html.o lex.yy.o -o cpp2html

cpp2html.o: cpp2html.c
    gcc -g -DDEBUG -c cpp2html.c

lex.yy.o: lex.yy.c
    gcc -g -c lex.yy.c

lex.yy.c: cppscanner.l
    flex cppscanner.l -o lex.yy.c
于 2013-11-12T03:38:37.087 回答