makefile question

This is a discussion on makefile question within the C++ Programming forums, part of the General Programming Boards category; Hi I have some basic questions about makefile. The makefile I wrote looks like this Code: CC = g++ target ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    3

    makefile question

    Hi

    I have some basic questions about makefile. The makefile I wrote looks like this

    Code:
    CC = g++
    target = card.exe
    
    all : $(target)
    
    $(target) : main.o card.o cardItem.o
    	$(CC) -Wall main.o card.o cardItem.o -o $(target)
    
    card.o : card.h card.cpp 
    	$(CC) -c card.cpp card.h 
    	
    cardItem.o : cardItem.cpp cardItem.h 
    	$(CC) -c cardItem.cpp cardItem.h 
    	
    clean :
    	-rm *.o $(target)
    cardItem.h is linked with card.h ie. inside cardItem.h I have #include "card.h". Does that mean the dependence list of cardItem.o also need to include card.h and card.cpp?

    Also do I need to have -Wall for card.o and cardItem.o in order to have the compile check all the code?

    Cheers

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Remove the .h files from the $(CC) lines.
    You don't compile them directly, they're #included by the source.

    > Also do I need to have -Wall for card.o and cardItem.o in order to have the compile check all the code?
    No, it's too late for -Wall to do it's job when you're combining .o files into an executable.
    Add -Wall to the $(CC) lines (along with the -c option).

    Investigate the $CFLAGS make variable.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Compilation Question
    By chacham15 in forum C Programming
    Replies: 10
    Last Post: 10-12-2008, 08:15 PM
  2. A question about an interesting Makefile
    By meili100 in forum Tech Board
    Replies: 2
    Last Post: 08-12-2008, 03:56 PM
  3. about Makefile and Macro
    By tom_mk in forum C++ Programming
    Replies: 1
    Last Post: 09-18-2003, 01:07 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Makefile Newbie: Inheritance Question
    By Ashes999 in forum C++ Programming
    Replies: 2
    Last Post: 07-10-2003, 02:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21