Make: *** No rule to make target 'foo.c', needed by 'foo.o'. Stop.
make was asked to build a file for which there is no rule and no existing file — a missing source, a typo in the Makefile, or a stale dependency.
No rule to make target*** No rule to make targetneeded by . Stop.make: *** No targets specified and no makefile foundninja: error: 'x.cpp', needed by 'x.o', missing and no known rule to make it Meaning
The message names the missing file and what needs it. Typical causes: the file was renamed or deleted but is still listed in the Makefile or in an old .d dependency file, a wrong relative path, or make is run from the wrong directory. After refactoring, a stale generated .d file is a classic reason.
Common causes
- Source or header listed in the Makefile does not exist (renamed, deleted, wrong case)
- Running
makefrom a different directory than the Makefile's - Stale
.ddependency files mentioning a removed header - Typo in a target or variable name
- Generated file whose rule is missing
⚡ Quick fix
- Check the file exists at the named path (
ls) - Run
make clean(or delete*.d) and rebuild - Run
makefrom the folder that holds the Makefile, or usemake -C dir
Detailed fix by platform
Make
make -nprints what would run;make -p | lessshows all rules;make --debug=bexplains decisions- Remove dependency files:
find . -name '*.d' -delete
CMake
- Re-run
cmake -S . -B buildafter adding or removing source files, thencmake --build build
Code examples
Rule and dependency basics
CC = gcc
OBJS = main.o util.o
app: $(OBJS)
$(CC) -o $@ $(OBJS)
%.o: %.c
$(CC) -c $< -o $@
# "No rule to make target 'util.c', needed by 'util.o'" => util.c is missing or misspelledHow to diagnose
- Name — Which file does make name?
- Disk — Does that path exist?
- Stale — Old .d or generated files?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Could not find a package configuration file CMake Error: Could not find a package configuration file provided by "Foo" (requested version 1.2)
- fatal error: No such file or directory C/C++: fatal error: foo.h: No such file or directory — #include not found
- missing separator Make: Makefile:5: *** missing separator. Stop. (spaces instead of a tab)
Most viewed in C/C++
- terminate called after throwing an instance of C++: terminate called after throwing an instance of 'std::out_of_range' — what(): vector::_M_range_check
- double free or corruption C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped)
- expected ';' before C/C++: error: expected ';' before 'x' — missing semicolon
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026