Utilizing the Make Command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:
  • Compile cpp2html.c to produce cpp2html.o.
    ( Important: the source code in these files is C, not C++, and so must be compiled and linked with gcc, not g++.)
  • Run the command

    flex cppscanner.l

    to produce the file lex.yy.c from the language description in cppscanner.l.
  • Compile lex.yy.c to produce lex.yy.o. (This often produces a warning message about extra tokens. Ignore it.)
  • Link the the .o files to produce an executable program named cpp2html
  • Write a makefile that will carry out these steps. Your makefile should result in only the minimum required amount of steps when any input file to this process is changed.
  1. Relevant commands, code, scripts, algorithms:
    Nothing outside of the UNIX command library

  2. The attempts at a solution (include all code and scripts):
    My makefile

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

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

cpp2html: cpp2html.o lex.yy.o
	gcc -g -DDEBUG cpp2html.o lex.yy.o
	mv a.out cpp2html

And here is the error I get when I get my makefile checked for completion:

Your makefile does not build 'cpp2html' when invoked:
gcc -g -DDEBUG -c cpp2html.c
flex cppscanner.l

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Old Dominion University, Norfolk (Virginia), USA, Mr. Zeil, CS 252

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Your makefile contains rules for creating cpp2html.o from cpp2html.c, lex.yy.o from lex.yy.c, and cpp2html from cpp2html.o and lex.yy.o.

The second bullet in your problem statement talks about creating lex.yy.c. Do you have a rule that builds lex.yy.c if the contents of its dependencies have changed since the last time you ran make?

When you ran make, did it produce any error messages?

1 Like

I removed this line "flex cppscanner.l" from the makefile and ran it through the shell and it produced the lex.yy.c file. So then I save and do "make" to update everything and then "make cpp2html" to produce the program which after doing "ls" in shell I see it produced but when I run the checker I get the same error:

Your makefile does not build 'cpp2html' when invoked:
gcc -g -DDEBUG -c cpp2html.c

I guess I need to do a command to make lex.yy.c in the makefile but just typing flex cppscanner.l in the makefile and running doesn't do it.

EDIT: I was able to solve and complete this task. Thanks for you help.

Yes, you need a rule to make lex.yy.c in the makefile. If you manually type:

flex cppscanner.l

before invoking make, that kind of defeats the purpose of using make, doesn't it?

If you invoke make without specifying a target operand on the command line, how does make decide what target(s) need(s) to be built?

Yeah. I just misread the instructions. Thanks Don !

How did you compete this? This problem is driving me mad! I wish this class was taught in a classroom.

Moderator comments were removed during original forum migration.

If you look at the 1st message in this thread, you will see that the way to solve this problem is taught in a classroom at Old Dominion University, in Norfolk (Virginia), in the USA, in a class taught by Mr. Zeil. The name of the class is CS 252. From that name, I assume it is a computer science class at the sophomore level.

You might be interested in the little introduction to make i once wrote.

I hope this helps.

bakunin