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
4 Answers
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:
- The source code file must exist in the directory where you are trying to run the make command.
- 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. ;-)
-
-
-
this doesn't help me, I've done all of this and it still won't work for me Apr 28, 2020 at 9:40
-
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.
-
-
-
You officially kept me from ripping my own hair out and I'm bold. Thank you so much Sep 26, 2022 at 22:11
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!!!
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.
-
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 :)– RuddyDevMay 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.– kwestyJan 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 BJun 27, 2022 at 22:14
ls -al
, get a snapshot and post it in the question?