gcc makefile error: "No rule to make target ..."
GccMakefileGcc Problem Overview
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
Gcc Solutions
Solution 1 - Gcc
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.
Solution 2 - Gcc
In my experience, this error is frequently caused by a spelling error.
I got this error today.
> make[1]: *** No rule to make target maintenaceDialog.cpp', needed by
maintenaceDialog.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.
Solution 3 - Gcc
The more common reason for this message to be printed is because you forgot to include the directory in which the source file resides. As a result, gcc "thinks" this file does not exist.
You can add the directory using the -I
Solution 4 - Gcc
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
fixed it.
Solution 5 - Gcc
Is that it exactly? Remember that Makefile syntax is whitespace aware and requires tabs to indent commands under actions.
Solution 6 - Gcc
One of frequent mistakes might be typo in another file name.
You example is quite straightforward but what may sometimes confuse are
messages of make
itself. Lets consider an example.
My folder contents is:
$ ls -1
another_file
index.md
makefile
Whereas my makefile
looks like
all: index.html
%.html: %.md wrong_path_to_another_file
@echo $@ $<
Although I do have index.md
where it should be and there is no mistake in the name of it, the message from make
will be
make: *** No rule to make target `index.html', needed by `all'. Stop.
To be honest the message is confusing. It just says, that there is no rule. In fact, it means that the rule is wrong, but due to wildcard (pattern) rules make
cannot determine what exactly caused the issue.
Lets alter makefile
a little, which is to say replace patterns with explicit rules:
index.html: index.md wrong_path_to_another_file
And now the message we get will be:
make: *** No rule to make target `wrong_path_to_another_file', needed by `index.html'. Stop.
Miracle! The following might be concluded:
-
Messages of
make
depends on rules and does not always point to the root of problems -
There might be other problems in your
makefile
different from specified by this message
Now we've come up with the idea of checking other dependencies in a rule as well:
all: index.html
%.html: %.md another_file
@echo $@ $<
Only this will provide us with the desired result:
$ make
index.html index.md
Solution 7 - Gcc
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.
Solution 8 - Gcc
In my case it was due to a multi-line rule error in the Makefile. I had something like:
OBJS-$(CONFIG_OBJ1) += file1.o file2.o \
file3.o file4.o \
OBJS-$(CONFIG_OBJ2) += file5.o
OBJS-$(CONFIG_OBJ3) += file6.o
...
The backslash at the end of file list in CONFIG_OBJ1
's rule caused this error. It should be like:
OBJS-$(CONFIG_OBJ1) += file1.o file2.o \
file3.o file4.o
OBJS-$(CONFIG_OBJ2) += file5.o
...
Solution 9 - Gcc
In my case it was due to I crated file like MakeFile
instead it should be Makefile
.
Solution 10 - Gcc
If you are trying to build John the Ripper "bleeding-jumbo" and get an error like "make: *** No rule to make target 'linux-x86-64'". Try running this command instead: ./configure && make
Solution 11 - Gcc
In my case, the error message referred to an old filename, which did no longer exist because it was renamed. It turned out that the outdated information did not come from the Makefile, but from files in .deps
directories.
I ran into this error after copying files from one machine to another. In that process, I assume the timestamps got in an inconsistent state, which confused "make" when running multiple jobs in parallel (similar to this bug report).
Sequential builds with make -j 1
were not affected, but it took me a while to realize because I was using an alias (make -j 8
).
To clean up the state, I removed all .deps
files and regenerated the Makefile. These are the commands that I used:
find | grep '.deps' | xargs rm
find | grep '.deps' | xargs rmdir
autoreconf --install # (optional, but my project is using autotools)
./configure
After that, building worked again.
Solution 12 - Gcc
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
Solution 13 - Gcc
Another example of a weird problem and its solution:
This:
target_link_libraries(
${PROJECT_NAME}
${Poco_LIBRARIES}
${Poco_Foundation_LIBRARY}
${Poco_Net_LIBRARY}
${Poco_Util_LIBRARY}
)
gives: make[3]: *** No rule to make target '/usr/lib/libPocoFoundationd.so', needed by '../hello_poco/bin/mac/HelloPoco'. Stop.
But if I remove Poco_LIBRARIES
it works:
target_link_libraries(
${PROJECT_NAME}
${Poco_Foundation_LIBRARY}
${Poco_Net_LIBRARY}
${Poco_Util_LIBRARY}
)
I'm using clang8 on Mac and clang 3.9 on Linux The problem only occurs on Linux but works on Mac!
I forgot to mention: Poco_LIBRARIES
was wrong - it was not set by cmake/find_package!
Solution 14 - Gcc
In my case the path is not set in VPATH, after added the error gone.
Solution 15 - Gcc
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.
https://stackoverflow.com/questions/30503532/c-why-people-dont-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.
Solution 16 - Gcc
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.
Solution 17 - Gcc
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.
Solution 18 - Gcc
In my case, the source and/or old object file(s) were locked (read-only) by a semi-crashed IDE or from a backup cloud service that stopped working properly. Restarting all programs and services that were associated with the folder structure solved the problem.
Solution 19 - Gcc
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.
Solution 20 - Gcc
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
Solution 21 - Gcc
In my case, it was due to me calling the Makefile: MAKEFILE (all caps)