3

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

  • 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 '15 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 – Joseph Aaron Woodward Jul 29 '15 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 '15 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. – Joseph Aaron Woodward Jul 29 '15 at 1:02
  • @JosephAaronWoodward you can mark the answer as accepted now by clicking the gray check mark next to it. – ChrisG Jul 29 '15 at 9:29
13

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. ;-)

| improve this answer | |
  • Thanks so much! – thebunnyrules Feb 15 '17 at 15:57
  • I appreciate thorough answers like this. – EJ Mak Apr 21 '17 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 at 9:40
  • @Godsspeed please create a new question with your specific issues. – Cliff B Apr 28 at 16:36
1

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.

| improve this answer | |
  • 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 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 – Joseph Chou Jul 15 at 4:59

You must log in to answer this question.

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