# Make: *** No rule to make target 'foo.c', needed by 'foo.o'. Stop.

**Code:** `No rule to make target` · **Category:** C/C++ · **Seen on:** C/C++, Make, CMake

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/make-no-rule-to-make-target)
