可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
回答1:
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.
回答2:
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.
回答3:
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 argument to gcc.
回答4:
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.
回答5:
Is that it exactly? Remember that Makefile syntax is whitespace aware and requires tabs to indent commands under actions.
回答6:
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 ...
回答7:
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.
回答8:
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
回答9:
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 utterly wrong. 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:
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
回答10:
I got the same error when I only copy the Source directory to different location.
It was solved after I moved the Build directory too.
回答11:
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.
回答12:
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!
回答13:
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.
回答14:
In my case the path is not set in VPATH, after added the error gone.
回答15:
In my case, it was due to me calling the Makefile: MAKEFILE (all caps)