No rule to make target C/C++ Origin: Application & API Last updated 15 Oct 2026

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.

Exact message you may see 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
Seen on: C/C++ Make CMake

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 make from a different directory than the Makefile's
  • Stale .d dependency files mentioning a removed header
  • Typo in a target or variable name
  • Generated file whose rule is missing

⚡ Quick fix

  1. Check the file exists at the named path (ls)
  2. Run make clean (or delete *.d) and rebuild
  3. Run make from the folder that holds the Makefile, or use make -C dir

Detailed fix by platform

Make

  1. make -n prints what would run; make -p | less shows all rules; make --debug=b explains decisions
  2. Remove dependency files: find . -name '*.d' -delete

CMake

  1. Re-run cmake -S . -B build after adding or removing source files, then cmake --build build

Code examples

Rule and dependency basics

make
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 misspelled

How to diagnose

  1. Name — Which file does make name?
  2. Disk — Does that path exist?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

Could not find a package configuration file — CMake Error: Could not find a package configuration file provided by "Foo" (requested version 1.2) (C/C++)Could not find a pack…fatal error: No such file or directory — C/C++: fatal error: foo.h: No such file or directory — #include not found (C/C++)fatal error: No such …missing separator — Make: Makefile:5: *** missing separator. Stop. (spaces instead of a tab) (C/C++)missing separatornot a member of std — C++: error: 'optional' in namespace 'std' does not name a template type — wrong -std standard (C/C++)not a member of stdredefinition of — C++: error: redefinition of 'class X' / multiple definition — missing include guard (C/C++)redefinition ofundefined reference to — C/C++: undefined reference to `function' — collect2: error: ld returned 1 exit status (C/C++)undefined reference toundefined reference to main — C/C++: undefined reference to `main' — (.text+0x20) in crt1.o (C/C++)undefined reference t…No rule t…

Explore the map of this error Full error map →

🧠 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.