Archived

This topic is now archived and is closed to further replies.

chadmv

multiple executables in a makefile

Recommended Posts

Hi, I'm trying to get my makefile to compile 3 different executables...but I'm having trouble. Heres what I have PROGS = frequencies huffman encode OBJS = frequencies.o huffman.o encode.o all: $(OBJS) g++ -o $(PROGS) $(OBJS) frequencies.o: frequencies.cpp g++ -c frequencies.cpp huffman.o: huffman.cpp g++ -c huffman.cpp encode.o: encode.cpp g++ -c encode.cpp clean: rm -f $(EXES) $(OBJS) but that all target doesnt work. How do I make it compile each executable? And there are tabs on those code lines...the post seemed to have taken them out... [edited by - chadmv on April 20, 2004 12:49:13 AM]

Share this post


Link to post
Share on other sites
You just can''t compile multiple targets with one invocation of gcc that way. You might be able to hack it using ''xargs'' (this is a unix thing and I don''t know enough about it to really help), but I think what you really need is something more like:

PROGS = frequencies huffman encode
OBJS = frequencies.o huffman.o encode.o
all: $(PROGS)
frequencies: frequencies.o
g++ -o frequencies frequencies.o
frequencies.o: frequencies.cpp
g++ -c frequencies.cpp
huffman: huffman.o
g++ -o huffman huffman.o
huffman.o: huffman.cpp
g++ -c huffman.cpp
encode: encode.o
g++ -o encode encode.o
encode.o: encode.cpp
g++ -c encode.cpp
clean:
rm -f $(PROGS) $(OBJS)

(I can''t type tabs apparently. But you know where they go )

Basically, I made a target for each individual app, and set up "all" recursively to build those targets.

Share this post


Link to post
Share on other sites