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
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.
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. ;-)
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.
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
If not type
cd mario-more and press enter and then you are all set to execute the make command.