gcc makefile error: "No rule to make target ..."
I'm trying to use GCC (linux) with a makefile to compile my project.
I get the following error which is can't seem to decipher in this context:
"No rule to make target 'vertex.cpp', needed by 'vertex.o'. Stop."
This is the makefile:
a.out: vertex.o edge.o elist.o main.o vlist.o enode.o vnode.o g++ vertex.o edge.o elist.o main.o vlist.o enode.o vnode.o main.o: main.cpp main.h g++ -c main.cpp vertex.o: vertex.cpp vertex.h g++ -c vertex.cpp edge.o: edge.cpp edge.h g++ -c num.cpp vlist.o: vlist.cpp vlist.h g++ -c vlist.cpp elist.o: elist.cpp elist.h g++ -c elist.cpp vnode.o: vnode.cpp vnode.h g++ -c vnode.cpp enode.o: enode.cpp enode.h g++ -c node.cpp
That's usually because you don't have a file called
vertex.cpp available to make. Check that:
- that file exists.
- you're in the right directory when you make.
Other than that, I've not much else to suggest. Perhaps you could give us a directory listing of that directory.
Read more... Read less...
In my experience, this error is frequently caused by a spelling error.
I got this error today.
make: *** No rule to make target
maintenaceDialog.cpp', needed bymaintenaceDialog.o'. Stop.
In my case the error was simply a spelling error. The word MAINTENANCE was missing it's third N.
Also check the spelling on your filenames.
In my case I had bone-headedly used commas as separators. To use your example I did this:
a.out: vertex.o, edge.o, elist.o, main.o, vlist.o, enode.o, vnode.o g++ vertex.o edge.o elist.o main.o vlist.o enode.o vnode.o
Changing it to the equivalent of
a.out: vertex.o edge.o elist.o main.o vlist.o enode.o vnode.o g++ vertex.o edge.o elist.o main.o vlist.o enode.o vnode.o
Is that it exactly? Remember that Makefile syntax is whitespace aware and requires tabs to indent commands under actions.
The problem I found was even sillier than what other folks have mentioned.
Our makefiles get passed lists of things to build. Someone added
TheOtherLibrary to one of the lists, as shown below.
LIBRARYDIRS = src/Library LIBRARYDIRS = src/TheOtherLibrary
They should have done this:
LIBRARYDIRS = src/Library LIBRARYDIRS += src/TheOtherLibrary
Had they done it the second way, they would not have wiped out the
Library build. The plus in
+= is very important.