0
votes

Keep getting an error on this make file saying "No rule to make target '/Main.cpp', needed by 'Main.o'

    HOME = /home/
    CC = g++ -Wall -pedantic
    PROJ = $(HOME)/Proj1
    INCL = -I $(PROJ)
    all: main.x
    main.x: List.o Summary.o Main.o
    < TAB >:$(CC) -o main.x List.o Summary.o Main.o
    List.o: $(PROJ)/List.h $(PROJ)/List.cpp
    < TAB >$(CC) -c $(INCL) $(PROJ)/List.cpp

    Summary.o: $(PROJ)/Summary.h $(PROJ)/Summary.cpp
    < TAB >$(CC) -c $(INCL) $(PROJ)/Summary.cpp


    Main.o: $(PROJ)/Main.cpp
    < TAB >$(CC) -c $(INCL) $(PROJ)/Main.cpp
    clean:
    < TAB >rm -rf *.o *~ *.x

thanks!

2
Are you sure this is EXACTLY the makefile you're using, and the exact error you're seeing? It looks to me like you've misspelled or reset the PROJ variable somewhere, so that the prerequisite $(PROJ)/Main.cpp is expanding to just /Main.cpp.MadScientist
This Makefile looks ok. You've editied it by adding < TAB > , is there anything else you have edited, or is this the exact same Makefile you're actually using ?nos
This is the exact makefile im using. Just took my last name out of the proj extensionRob
Does the first command line for your main.x target really start with a colon (i.e. :$(CC) -o main.x ...)? Not sure what that's supposed to mean... Although that probably is unrelated to your question...twalberg
@Rob Do you have a space in your last name, or between your first and last name, or anyhere else after the PROJ = $(HOME)/Proj1 part?nos

2 Answers

1
votes

There are two possibilities I see. The first one is that you have some extraneous whitespace at the end of the PROJ variable definition. In make, all extra whitespace at the end of a line is preserved. So if you write this:

PROJ = $(HOME)/Proj1   # some whitespace at the end

the value of the variable will be '$(HOME)/Proj1 ' (including the spaces--no quotes though). Then when you use it in your prerequisite list:

Main.o: $(PROJ)/Main.cpp

it expands to:

Main.o: $(HOME)/Proj1   /Main.cpp

which is two different prerequisites: the directory, and the non-existent file /Main.cpp.

If that's not it, then the makefile you've shown us is different in some material way from the one you're using, because the one you've shown us should not display that error.

0
votes

Make sure /home/Proj1/Main.cpp is present, otherwise the Makefile looks fine. $(PROJ)/Main.cpp points to /home/Proj1/Main.cpp