mihajlv
mihajlv

Reputation: 2315

How to link files in different folders produced by calling multiple make files?

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.

Upvotes: 1

Views: 407

Answers (1)

C.G.
C.G.

Reputation: 61

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

Upvotes: 1

Related Questions