1

I'm new to using makefiles for my projects, and I decided to start since I got tired of writing out all of the commands and arguments.

The current makefile that I have looks like this:

run_program:
        CUDA_VISIBLE_DEVICES=1
        python DIR/main.py --setup2

When I run this program using the following command:

make run_program

I get the following error:

make: *** No rule to make target 'run_program'.  Stop

I've made sure that the makefile is in the appropriate directory and that there are no spelling errors of the sort, but I'm having trouble figuring out what I did wrong. I've checked others answers such as gcc makefile error: “No rule to make target …” but I'm not sure how to apply it to my case.

Any tips or advice are greatly appreciated. Thanks in advance.

Sean
  • 2,890
  • 8
  • 36
  • 78
  • How odd. What happens when you just `make`? – Beta Nov 14 '19 at 01:52
  • I receive the error message `make: *** No targets specified and no makefile found. Stop.` – Sean Nov 14 '19 at 01:53
  • Curiouser and curiouser. What is the name of your makefile? – Beta Nov 14 '19 at 02:13
  • The name of my makefile is `make.mk`. – Sean Nov 14 '19 at 02:17
  • I have another makefile named `makefile.mk` and this doesn't work either. :( – Sean Nov 14 '19 at 02:17
  • I found the problem. Apparently I need to add the `-f` option and it runs. But... Why is this the case? Is this normal behavior for makefiles? – Sean Nov 14 '19 at 03:44
  • When you `make`, Make doesn't know which makefile you're thinking of. You can specify a makefile with `-f`, and if you don't, [Make will search for a couple of variants of "Makefile"](https://www.gnu.org/software/make/manual/make.html#Makefile-Names). – Beta Nov 15 '19 at 00:24

1 Answers1

2

Per 'make' info page:

make executes commands in the makefile to update one or more target names, where name is typically a program. If no -f option is present, make will look for the makefiles GNUmakefile, makefile, and Makefile, in that order.

If you name your makefile in other name, you will have to use the '-f'. While this is a good practice to name makefiles with '.mk' suffix (e.g., makefile for sub projects), most projects will name the "main" makefile to match on the the defaults, usually 'Makefile'.

dash-o
  • 13,723
  • 1
  • 10
  • 37