Byrn
Byrn

Reputation: 11

creating makefile in unix

I have been working on this problem for a while, I could use a little help:

The steps necessary to produce this program are:

Compile cpp2html.c to produce cpp2html.o. (Important: the source code in this project 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.

these are the errors/warnings I get when compiled,

gcc: warning: cpp2html.o: linker input file unused because linking not done
gcc: warning; lex.yy.o: linker input file unused because linking not done
mv: cannot stat `a.out': No such file or directory

this is what I have in my makefile:

enter code here

#
CPPFLAGS=-g -DDEBUG
#

#
cpps2html: cpp2html.o lex.yy.o
     gcc $(CPPFLAGS) -c cpp2thml.o lex.yy.o
     mv a.out cpp2html

cpp2thml.o: cpp2html.c
     gcc &(CPPFLAGS) -c cpp2html.c

lex.yy.c: cppscanner.l
    flex cppscaner.l

lex.yy.o: lex.yy.c
     gcc $(CPPFLAGS) -c lex.yy.c

Upvotes: 0

Views: 377

Answers (1)

Wintermute
Wintermute

Reputation: 44013

This

 gcc $(CPPFLAGS) -c cpp2thml.o lex.yy.o
 mv a.out cpp2html

should be

 gcc $(CPPFLAGS) -o cpp2html cpp2thml.o lex.yy.o

Certainly the -c option (which means "don't attempt linking") is bad here.

Side note: Using CPPFLAGS, which is conventionally reserved for options for the C preprocessor, is a bit odd in a linking command. It's not illegal, but the normal distribution is to use

  • CPPFLAGS for stuff that the preprocessor uses (such as -Dfoo or -Isomewhere)
  • CFLAGS for stuff the C compiler uses (such as -g)
  • LDFLAGS for linker flags (such as -Lsomewhere)
  • LDLIBS for libraries (-lfoo)

And then use them where pertinent (or use predefined rules, which use them appropriately). This usually means CPPFLAGS and CFLAGS when building .o targets and CFLAGS, LDFLAGS and LDLIBS when linking.

Upvotes: 1

Related Questions