Need help using Makefile in Mac Terminal

17,867

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.

Share:
17,867
ivesingh
Author by

ivesingh

Updated on June 04, 2022

Comments

  • ivesingh
    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
      Beta over 10 years
      If 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
      ivesingh over 10 years
      What are they telling me anyways? This is my first time using terminal. I have emacs what command do I enter and where?
    • Jonathan Leffler
      Jonathan Leffler over 10 years
      The Makefile isn't going to help much; there isn't going to be a rule that builds a program d from a source file dijkstra.c in the built-in rules. You'd either need dijkstra: dijkstra.c (which would probably work), or you can simply type make dijkstra and it will work. (As written, the target d will never be created, but if the file dijkstra.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 run make, nothing will be executed.