Need help using Makefile in Mac Terminal
You don't have to use the terminal for everything.
Start up your standard text editor, such as TextEdit, type in exactly what your instructions say. NOTE: for a Makefile to work properly, the indented line must start with a tab, not with spaces. Save the file with filename of Makefile
- no '.txt' or anything like that - in the same directory as your dijkstra.c file.
Ignore the "clean" and "test" suggestions for the moment.
Edit dijkstra.c according to your instructions.
Then open a terminal. If your Makefile and dijkstra.c are not in your home directory, then type cd path_to_correct_directory
, only use the actual path to the correct directory; cd
stands for "change directory (to)".
Once you're in the right directory, you should be able to type make
, and your project will be compiled. Well, more likely, in fact, you will see errors - programming is like that, especially when you're just starting out. Read the errors very carefully, think about what they mean, and then try to fix just the first one. Then run make
again. Repeat.
Once you've had a successful compile, work on getting your program to run correctly.
Then read up on Makefiles and add the "clean" rule, and once that's working, the "test" rule.
Good luck and have fun.
Programming can be difficult to grok initially - but once you get it, there's nothing better.
ivesingh
Updated on June 04, 2022Comments
-
ivesingh almost 2 years
I am so new into this and we are assigned a new project. I am having hard time understanding how to start entering my code with the following commands that are given. Can anyone please direct me what exactly I need to enter into the terminal. Please note I am not asking any for the code in my actual project but this is just something that I need to in order to get started.
Create a file named Makefile with the contents:
CFLAGS = -ansi -Wall -g -O0 -Wwrite-strings -Wshadow -pedantic-errors -fstack-protector-all d: dijkstra.c
Add
main()
to dijkstra.c and proceed. You should, but are not required to, add a “clean” and “test” target to the Makefile.-
Beta over 10 yearsIf you don't have a text editor, you're going to have a hard time. I suggest you try entering the command
emacs
, and see what happens. -
ivesingh over 10 yearsWhat are they telling me anyways? This is my first time using terminal. I have emacs what command do I enter and where?
-
Jonathan Leffler over 10 yearsThe
Makefile
isn't going to help much; there isn't going to be a rule that builds a programd
from a source filedijkstra.c
in the built-in rules. You'd either needdijkstra: dijkstra.c
(which would probably work), or you can simply typemake dijkstra
and it will work. (As written, the targetd
will never be created, but if the filedijkstra.c
exists, it won't fail either.) If you ask whether things are up to date (make -q
), the answer will be 'No', but when you runmake
, nothing will be executed.
-