c++ - Compiling multiple executables with make -
i following makefile capable of compiling multiple executables:
cxx = clang++ cxxflags = -g -wall --std=c++11 objs = two_rung.o three_rung.o dumbinterp.o interp.o writeladdermpo.o prog = two_rung three_rung dumbinterp interp sources = two_rung.cc three_rung.cc dumbinterp.cc interp.cc writeladdermpo.cc heads = writeladdermpo.h includes = -i $(home)/itensor libs = -l $(home)/itensor/lib -litensor -lstdc++ -framework accelerate all: $(prog) $(prog): $(objs) $(cxx) $(includes) -o $(prog) $(objs) $(libs) %.o: %.cc $(heads) $(cxx) $(includes) -c -o $(objs) $(sources)
the executables denoted prog
. when try make 1 of these executables, example interp
, instead
computer:folder username$ make interp clang++ -i /users/username/itensor -c -o two_rung.o three_rung.o dumbinterp.o interp.o writeladdermpo.o two_rung.cc three_rung.cc dumbinterp.cc interp.cc writeladdermpo.cc
which say, make tossing files in when call them variables, totally makes perfect sense. want behave like:
clang++ -i /users/username/itensor -c -o interp.o interp.cc
and then
clang++ -i /users/username/itensor -o interp interp.o -l $(home)/itensor/lib -litensor -lstdc++ -framework accelerate
how make this? thanks!
to expand on comments.
consider rule
$(prog): $(objs) $(cxx) $(includes) -o $(prog) $(objs) $(libs)
this expanded make
into
two_rung three_rung dumbinterp interp: two_rung.o three_rung.o dumbinterp.o interp.o writeladdermpo.o clang++ -i $(home)/itensor -o two_rung three_rung dumbinterp interp two_rung.o three_rung.o dumbinterp.o interp.o writeladdermpo.o -l $(home)/itensor/lib -litensor -lstdc++ -framework accelerate
not quite had in mind think.
instead need specify each executable target , dependencies explicitly:
two_rung: two_rung.o writeladdermpo.o three_rung: three_rung.o writeladdermpo.o dumbinterp: dumbinterp.o writeladdermpo.o interp: interp.o writeladdermpo.o
with flag variables set correctly make
link correctly.
as compilation of source files object files, have problems there too, where
%.o: %.cc $(heads) $(cxx) $(includes) -c -o $(objs) $(sources)
will expanded to
%.o: %.cc writeladdermpo.h clang++ -i $(home)/itensor -c -o two_rung.o three_rung.o dumbinterp.o interp.o writeladdermpo.o two_rung.cc three_rung.cc dumbinterp.cc interp.cc writeladdermpo.cc
that's not how work, need create each object file each source file separately. fortunately can still use same basic rule, don't need provide command create object file:
%.o: %.cc $(heads)
that's it, no command needed. need e.g.
cxxflags += $(includes)
before rule.
Comments
Post a Comment