tags:

views:

60

answers:

2

I have this Makefile and each line run OK separately, but when I do make I get this error:

make: *** No rule to make target `CoalitionManipulation‬‬.cpp', needed by `CoalitionManipulation‬‬.o'.  Stop.

But I can see the CoalitionManipulation.o file, it means it exists! Bere is the makefile:

CoalitionManipulation‬‬ : ‫‪CoalitionManipulation‬‬‬‬.o PrintQ3.o ChooseRandomBit.o
  g++ -Wall -lm PrintQ3.o ChooseRandomBit.o CoalitionManipulation.o -o ‫‪CoalitionManipulation‬‬

CoalitionManipulation‬‬.o : CoalitionManipulation‬‬.cpp ChooseRandomBit.h PrintQ3.h
   g++ -Wall -c CoalitionManipulation.cpp -o CoalitionManipulation‬‬.o

PrintQ3.o : PrintQ3.h PrintQ3.cpp
   g++ -Wall -c PrintQ3.cpp -o PrintQ3.o

ChooseRandomBit.o : ChooseRandomBit.cpp ChooseRandomBit.h
   g++ -Wall -c ChooseRandomBit.cpp -o ChooseRandomBit.o

What is the problem?

+3  A: 

If you're using gmake (which is likely), you can define CXXFLAGS to be -Wall, and skip most of the .o rules (Make knows what to do with a .cpp file). You can actually leave the rule blank, but still specify the header dependencies without a problem.

EDIT: that's a rather different error than what was there at first... try the above and see if that works.

Try something like

CXXFLAGS=-Wall
CoalitionManipulation‬‬ : ‫‪CoalitionManipulation‬‬‬‬.o PrintQ3.o ChooseRandomBit.o
   g++ -Wall -lm $^ -o $@

CoalitionManipulation‬‬.o : CoalitionManipulation‬‬.cpp ChooseRandomBit.h PrintQ3.h
PrintQ3.o : PrintQ3.h PrintQ3.cpp
ChooseRandomBit.o : ChooseRandomBit.cpp ChooseRandomBit.h

clean:
    rm *.o CoalitionManipulation

The special variable $^ expands to the list of prerequisites, $@ expands to the target name.

Taken one step further, the automatic makefile generator will actually do linking for you as well if you just give it hints about which libraries to use, using LDLIBS. Secondarily, make will assume the .cpp file for both the final linking step and the steps in the middle.

CXXFLAGS=-Wall
LDLIBS=-lm
CoalitionManipulation‬‬: PrintQ3.o ChooseRandomBit.o
CoalitionManipulation‬‬.o: ChooseRandomBit.h PrintQ3.h
PrintQ3.o: PrintQ3.h
ChooseRandomBit.o: ChooseRandomBit.h
jkerian
+3  A: 
make: *** No rule to make target `CoalitionManipulation‬‬.cpp', needed by `CoalitionManipulation‬‬.o'.  Stop.

Make can't find CoalitionManipulation.cpp. Is it where you told make it is?

Philip Potter
all my files are in the same location including the Makefile
or.nomore