Jun 4, 2012 at 6:19pm UTC
I have two very similar makefiles for two similar projects, the first one works well, but i get following error message while running the second one:
make: *** No rule to make target `obj/Air.o', needed by `FoRM'. Stop.
----------------
//This works well!
CC=g++
MODEL=Radiation
DEPS = Weather.h Main.h AuxFuncs.h PathLength.h SunEarth.h Tree.h Trend.h
LIBS=-lm
CFLAGS=-O3 -fopenmp
ODIR=obj
_OBJ= Main.o AuxFuncs.o PathLength.o SunEarth.o Tree.o Trend.o Weather.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: %.cpp $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
$(MODEL): $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
all: $(MODEL)
.PHONY: clean
clean:
rm -f $(ODIR)/*.o
rm -f $(MODEL)
run: all
./$(MODEL)
-------------------------------------------------------
//This doesn't work
CC=g++
MODEL=FoRM
DEPS = Air.h AuxFuncs.h ForestPhysics.h FoRM.h Parameters.h Solar.h Terrain.h Tree.h Constant.h
LIBS=-lm
CFLAGS=-O3 -fopenmp
ODIR=obj
_OBJ= Main.o Air.o AuxFuncs.o FoRM.o Solar.o Parameters.o Terrain.o Tree.o ForestPhysics.o
OBJ= $(patsubst %,$(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: %.cpp $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
$(MODEL): $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
all: $(MODEL)
.PHONY: clean
clean:
rm -f $(ODIR)/*.o
rm -f $(MODEL)
run: all
./$(MODEL)
-----------------------------------------
I'm really confused!
Thanks for any help!
Last edited on Jun 4, 2012 at 6:21pm UTC
Jun 4, 2012 at 8:27pm UTC
Perhaps you have a stray character that doesn't display in the second one. Try hex dumping the two makefiles to see. This has happened to me a few times.
Another option is to turn on make's debug (usually -d).
Jun 5, 2012 at 1:57am UTC
seeing as it complains about Air.o and not Main.o... are you sure Air.cpp is in the directory that Main.cpp is in?
Jun 5, 2012 at 3:28am UTC
Yes Air.cpp is there.!
If I set "ODIR=." instead of "ODIR=obj", both files work well!
but I prefer to have object files in a separate directory like "obj".
That's weird to me!
Jun 5, 2012 at 1:35pm UTC
Great! Stray character!![SOLVED]
Thanks kooth!