1

I have the following make file

all:    XmlNode.o y.tab.o   y.tab.o lex.yy.o
    gcc -g -o prog y.tab.o lex.yy.o XmlAttributeNode.o XmlNode.o -ll -ly -lm

XmlNode.o:  
    cd XmlNode; make
y.tab.o: y.tab.c
    gcc -g -c y.tab.c
lex.yy.o: lex.yy.c
    gcc -g -c lex.yy.c
y.tab.c: LexYacc/prog1.y
    bison -y -dv LexYacc/prog1.y
lex.yy.c: LexYacc/prog1.l
    lex -l LexYacc/prog1.l

clean:
    rm -f y.tab.* lex.yy.* *.o prog 

XmlAttributeNode.o and XmlNode.o are made in the XmlNode folder, thus I get the error

gcc: XmlAttributeNode.o: No such file or directory
gcc: XmlNode.o: No such file or directory

I looked at the following questions 1, 2, and 3, but I can't seem to find how I can get a list of all the .o files produced by XmlNode.o so 1) I don't have to type them by hand and 2) the proper path is included so gcc can find the .o files. So something like this:

 XmlNode.o: 
    cd XmlNode; XmlNodeList = .o files from this make; XmlPath = `pwd`;

and then:

 all:   XmlNode.o y.tab.o   y.tab.o lex.yy.o
    gcc -g -o prog y.tab.o lex.yy.o XmlPath/XmlNodeList -ll -ly -lm

Any help would be appreciated.

Community
  • 1
  • 1
mihajlv
  • 2,275
  • 4
  • 36
  • 59
  • 1
    Have you read [Recursive Make Considered Harmful](http://miller.emu.id.au/pmiller/books/rmch/)? – Adam Rosenfield May 14 '12 at 20:32
  • It seems useful information thanks. – mihajlv May 14 '12 at 20:55
  • So... in the `XmlNode.o` rule you want to run Make in `XmlPath/`, using `XmlPath/Makefile`, which will produce several .o files in `XmlPath/`, and then you want to use a list of those files in the main makefile? – Beta May 15 '12 at 14:05

1 Answers1

1

Assuming the info in the comments, this will at least work.

all:    XmlNode.o y.tab.o   y.tab.o lex.yy.o
    gcc -g -o prog y.tab.o lex.yy.o XmlNode/XmlAttributeNode.o XmlNode/XmlNode.o -ll -ly -lm

XmlNode/XmlAttributeNode.o XmlNode/XmlNode.o:  
    cd XmlNode; make
y.tab.o: y.tab.c
    gcc -g -c y.tab.c
lex.yy.o: lex.yy.c
    gcc -g -c lex.yy.c
y.tab.c: LexYacc/prog1.y
    bison -y -dv LexYacc/prog1.y
lex.yy.c: LexYacc/prog1.l
    lex -l LexYacc/prog1.l

clean:
    rm -f y.tab.* lex.yy.* *.o prog; cd XmlNode; make clean
C.G.
  • 61
  • 5