Thread: How to use a makefile

  1. #1
    Registered User
    Join Date
    Jan 2017
    Posts
    20

    How to use a makefile

    I've written a makefile and saved it under the name "MakeFile" (provided below) for my program. It's in the same folder as my programs.


    all: main


    main.o: main.cc Greetings.cc
    g++ -c -Werror main.cc


    Greetings.o: Greetings.cc Greetings.h
    g++ -c -Werror Greetings.cc


    main: main.o Greetings.o
    g++ -0 main main.o Greetings.o






    Now how do I actually use the makefile? I read that you should type in make [options] [target1 target2 ...]. What are options and target? As an experiment, I tried typing "make MakeFile" and I got an error as shown below.


    Conrados-MBP:~ conrados$ make MakeFile
    make: *** No rule to make target `MakeFile'. Stop.

  2. #2
    Registered User
    Join Date
    Jan 2017
    Posts
    20
    I'm using a Macbook pro and sublime text 3 for my text editor. I'm also using my computer's terminal to compile my code.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Code:
    make
    Code:
    make all
    Code:
    make -f makefile
    Edit: Added forth command.
    Code:
    make -f makefile all
    Try the above one at a time.

    Replace the word makefile with exactly what you named your makefile.
    Case likely make a difference.

    On Linux the normal name is Makefile not makefile.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to run gcc makefile in VC++
    By huda in forum C++ Programming
    Replies: 13
    Last Post: 03-03-2012, 03:28 AM
  2. Need help with makefile
    By New_Programmer in forum C++ Programming
    Replies: 5
    Last Post: 03-31-2009, 04:55 PM
  3. makefile
    By shuo in forum C++ Programming
    Replies: 1
    Last Post: 11-18-2007, 01:41 AM
  4. difference makefile makefile.am makefile.in
    By Bargi in forum Linux Programming
    Replies: 7
    Last Post: 10-28-2007, 02:08 PM
  5. makefile
    By natasha_adams in forum C Programming
    Replies: 1
    Last Post: 01-16-2006, 02:26 PM

Tags for this Thread