7

I keep receiving and the error message " *** no rule to make target 'mario' stop" when I try to make mario. Does anyone have any advice? I already typed in pwd and I'm in the Jharvard desktop. Any one? Thanks

5
  • 2
    Before anyone marks this as a duplicate, please consider this. I looked at earlier answers but many were too specific to a certain case, or not a good generic response to this issue. If someone finds a better answer, then yes, flag it as a duplicate. Otherwise, let's see if we can make this one the definitive answer for starting students. ;-)
    – Cliff B
    Jul 28, 2015 at 21:08
  • I have checked that I am in pset1 dropbox and the source code file is mario.c. When I type make mario, it continues to say no rule to make target stop still. and when I type ls it brings up the hello program i made in the first part of pset1 Jul 29, 2015 at 0:18
  • Can you please go to the directory where this is happening, run the make command, type in the following command: ls -al, get a snapshot and post it in the question?
    – Cliff B
    Jul 29, 2015 at 0:49
  • ok, it will compile now. So it seems the problem was that it saved mario.c on the desktop and the dropbox but the mario part was highlighted and the .c was not. After I highlighted the whole thing and resaved it as mario.c it worked. Jul 29, 2015 at 1:02
  • @JosephAaronWoodward you can mark the answer as accepted now by clicking the gray check mark next to it.
    – ChrisG
    Jul 29, 2015 at 9:29

4 Answers 4

20

This is a very common question asked by new students. The make command is used to compile the source code and generate an executable program. While there are complexities to this process (more explanation in later lessons), this answer will give a simple 'how-to' for the early lessons so that you can get started.

To use make to build your executable, the command is make myprogram (not myprogram.c). For this to work, the following has to be true:

  1. The source code file must exist in the directory where you are trying to run the make command.
  2. The name of the executable must match the name of the source code file, without the extension.

That's the default and simple way to build a program. For example, if you have a source code file called hello.c, you build it with make hello. If the source code file were hello1.c, then make hello would not work and you'd get the "no rule..." error because the filenames don't match. If hello.c is in a different directory, it would fail the same way. The filenames must match, except that you don't include the .c extension in the make command, and the source code MUST be in the same directory.

This is also how make works when there is no makefile.Later, you will learn about a file called makefile. This file is written by the programmer (or provided by the instructors) and contains text that will tell make how to build executables when filenames are different, when there are multiple files involved, and when there are other more complex issues involved. It will contain rules to explain how to take certain actions, based on the make command parameters. But that's for later (or you can google the subject).

If this answers your question, please accept this answer to remove the question from the unanswered question pool. Let's keep up on forum housekeeping. ;-)

4
  • Thanks so much! Feb 15, 2017 at 15:57
  • I appreciate thorough answers like this.
    – EJ Mak
    Apr 21, 2017 at 18:34
  • this doesn't help me, I've done all of this and it still won't work for me
    – Godsspeed
    Apr 28, 2020 at 9:40
  • @Godsspeed please create a new question with your specific issues.
    – Cliff B
    Apr 28, 2020 at 16:36
9

I thought I was in the correct directory, but I wasn't. (I’m a super newbie.)

Execute to show what workspace you’re in “print working directory”: pwd

Execute to "list": ls

Execute to “change directory” to mario-more or mario-less depending on the set you chose: cd mario-more

Execute to make mario: make mario

Execute to run mario: ./mario

Hope this helps someone.

3
  • it help me, thanks Apr 12, 2022 at 2:18
  • This saved me thank you
    – Lochay
    Aug 22, 2022 at 18:46
  • You officially kept me from ripping my own hair out and I'm bold. Thank you so much Sep 26, 2022 at 22:11
1

I had the same error and turns out I was in the root directory. You need to be in the mario-more directory to execute the make mario command. Just check if you $ sign has mario-more/ prefix. If not type cd mario-more and press enter and then you are all set to execute the make command. Happy Coding!!!

0

This answer did not work for me at all.

There IS a file called mario in my directory. I AM on the directory mario.

I try to compile and I get the same error this person did and apparently there is NOTHTING I can do to solve it. I've been digging for hours. Something is wrong.

4
  • Are you sure you've navigated to the right directory in your terminal window? The command cd ~/pset1/mario should get you there if that's the issue. If you still can't compile after that then I'm out of ideas haha. Good luck :)
    – RuddyDev
    May 29, 2020 at 4:49
  • The biggest indicator is if the terminal is says "~/pset1/mario/" every line. If it says something different than it is accessing a different directory. For me I went back to my terminal after my waking up my computer, and didn't realize that it went back to the default of "~/". Great advice Ruddy Jul 15, 2020 at 4:59
  • I'm having the same issue! did you find a solution?? I'm in the correct directory, everything.
    – kwesty
    Jan 17, 2021 at 18:12
  • You said that there's a file called "mario". That would be the executable file, not the source code file. Is there a file called "mario.c"? And is it all lower case? Remember, case matters too. Every letter must match case too. For example, if there's a file called "Mario.c", then "make mario" would fail but "make Mario" would succeed.
    – Cliff B
    Jun 27, 2022 at 22:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .