Fix No Targets Specified and No Makefile Found
In this article
The error "no targets specified and no makefile found" occurs when you run make in a directory that does not contain a file named Makefile (or makefile) and you did not specify a target on the command line. The fix is to either create a Makefile in that directory, navigate to the correct directory, or explicitly specify a makefile with the -f option.
What the Error Means
Make is a build automation tool that reads instructions from a file called a makefile. When you type make without arguments, it expects to find a file named GNUmakefile, makefile, or Makefile in the current directory (in that order). If none exists, make has no rules to execute and no targets to build, so it prints the error and exits with a non‑zero status.
The message is actually two separate diagnostics combined: "no targets specified" (because you didn't name a target on the command line) and "no makefile found" (because no default makefile exists in the current directory). Both conditions must be true for this exact error to appear. If you run make some_target without a makefile, you get a different error: make: *** No rule to make target 'some_target'. Stop.
Why Make Needs a Makefile
A makefile is a plain text file that contains rules. Each rule has a target (usually a file to build), prerequisites (files the target depends on), and commands (shell commands to build the target). For example, a simple makefile for a C program might look like:
hello: hello.c gcc -o hello hello.c
When you run make, it reads this file, sees the first target hello, and builds it if hello.c is newer than hello or if hello does not exist. Without a makefile, make has no instructions at all, so it cannot do anything.
How to Fix It
The correct fix depends on why the makefile is missing. Here are the most common scenarios and their solutions:
- You are in the wrong directory. If you cloned a project from a repository, the makefile is usually in the top‑level directory. Use
ls(ordiron Windows) to see the files. If you see aMakefileormakefile, change into that directory withcdand runmakeagain. - The makefile has a different name. Some projects use names like
Makefile.am(for automake) ormakefile.linux. You can tell make to use a specific file with the-foption:make -f Makefile.linux. - The project needs configuration first. Many open‑source projects require you to run
./configure(orcmake) to generate a makefile from a template. Check the project's README or INSTALL file for instructions. For CMake projects, you typically runcmake .thenmake. - You need to create a makefile. If you are writing your own program and have no makefile, you must create one. The simplest makefile for a single C file is:
all: gcc -o myprogram myprogram.c
Save that as Makefile and run make. For more complex projects, you may want to learn the full makefile syntax.
Common Causes and Misconceptions
One frequent misconception is that the error means your code is broken. It does not – it simply means make cannot find its instruction file. Another common cause is running make in a subdirectory where the makefile lives one level up. For example, if your project has a src/ directory and the makefile is in the parent, running make inside src/ will fail. You can either cd .. or run make -C .. to tell make to change to the parent directory first.
On Windows, the file might be named Makefile but with a different extension that Windows hides (e.g., Makefile.txt). If you created it with a text editor, ensure it is saved as Makefile with no extension. Also, be aware that make is case‑sensitive on Linux/macOS: makefile and Makefile are both accepted, but makeFile is not.
Alternatives to Make
If you are not committed to make, there are other build tools that may be easier or more suitable:
- CMake – generates makefiles or native build files for many platforms. You write a
CMakeLists.txtand runcmaketo generate a makefile (or a Visual Studio solution). - Ninja – a faster, simpler build system that uses
build.ninjafiles. It is often used with CMake. - Meson – a modern build system that is also used with Ninja.
- For simple projects, you can skip a build tool entirely and compile manually with a single command like
gcc -o myprogram myprogram.c.
Each tool has its own configuration file, but the principle is the same: you need a file that describes how to build your project.
Checking Your Makefile for Errors
Once you have a makefile, you may encounter other errors. The most common is missing separator, which means a line that should start with a tab character starts with spaces instead. Make requires commands to be indented with a tab, not spaces. If you copy a makefile from a website, the indentation may be lost. To fix it, open the file in a text editor and ensure the command lines begin with a tab.
Another common issue is No rule to make target 'clean' – this happens when you run make clean but the makefile does not define a clean target. Many makefiles include a clean rule to remove compiled files, but not all do. You can add one yourself:
clean: rm -f *.o myprogram
Always be careful with rm commands in makefiles – they can delete important files if misused.
Frequently Asked Questions
Why do I get "no targets specified" even though I have a Makefile?
This happens if the makefile exists but is empty, or if it contains only comments or variable definitions but no rules. Make needs at least one rule to have a target. Add a rule like all: with a command, or specify a target on the command line.
How do I specify a makefile with a different name?
Use the -f option: make -f mymakefile. You can also use --makefile=mymakefile. This is useful when you have multiple makefiles for different platforms.
What is the difference between Makefile and makefile?
There is no functional difference on Linux/macOS – make looks for both. However, on some case‑sensitive filesystems, only the exact names makefile and Makefile are recognized. The GNU make manual recommends using Makefile because it stands out in directory listings.
Can I run make without a makefile?
Yes, but only if you specify a target that has a built‑in rule. For example, make file.o will try to compile file.c using an implicit rule. However, for most purposes you need a makefile.
Why does make say "make: Nothing to be done for 'all'"?
This is not an error – it means the target 'all' is up to date. Make checks timestamps and only runs commands if a prerequisite is newer than the target. If you want to force a rebuild, use make -B or delete the target file.
I'm on Windows and don't have make. What should I do?
You can install GNU make via a package manager like Chocolatey (choco install make) or use a Windows port like GnuWin32. Alternatively, use a different build tool like CMake with Visual Studio or Ninja.