gcc makefile error: "No rule to make target ..."

Viewed 1340272

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
21 Answers

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.

Is that it exactly? Remember that Makefile syntax is whitespace aware and requires tabs to indent commands under actions.

In my case it was due to I crated file like MakeFile instead it should be Makefile.

In my case the path is not set in VPATH, after added the error gone.

In my case, the reason for this error was that a folder name had a space, renaming the folder solved the problem


Example:

~/foo bar/mymoduledir

renaming the folder foo bar to foo_bar:

~/foo_bar/mymoduledir

fixes the problem

There are multiple reasons for this error.

One of the reason where i encountered this error is while building for linux and windows.

I have a filename with caps BaseClass.h SubClass.h Unix maintains has case-sensitive filenaming convention and windows is case-insensitive.

C++ why people don't use uppercase in name of header files?

Try compiling clean build using gmake clean if you are using gmake

Some text editors has default settings to ignore case-sensitive filenames. This could also lead to the same error.

how to add a c++ file in Qt Creator whose name starts with capital letters ? It automatically makes it small letter

This message can mean many things clearly.

In my case it was compiling using multiple threads. One thread needed a dependency that another thread hadn't finished making, causing an error.

Not all builds are threadsafe, so consider a slow build with one thread if your build passes other tests such as the ones listed above.

My case was a missing $:

Instead of:

(LINK_TARGET): $(OBJS)

Should be:

$(LINK_TARGET): $(OBJS)

Edit:

I had this same problem, but now due to another reason, it was due to an echo command inside my .bashrc file.

This error occurred for me inside Travis when I forgot to add new files to my git repository. Silly mistake, but I can see it being quite common.

In my case the issue popped out after removing some of the header files and .c files and the project didn't compile.

Running clean and then build compiled the project

Related