Question About Makefiles

This is a discussion on Question About Makefiles within the Linux Programming forums, part of the Platform Specific Boards category; How would I create a makefile with three .cc files? Would something like this be right? Code: Prog1: main.o Rational.o ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    5

    Question About Makefiles

    How would I create a makefile with three .cc files? Would something like this be right?

    Code:
     
    Prog1: main.o Rational.o test.o
            g++ -Wall -W -Werror main.o Rational.o test.o -o Prog1 
    
    
    main.o: main.cc Rational.h
            g++ -Wall -W -Werror -c main.cc -o Rational.o
    
    Rational.o: Rational.cc Rational.h
            g++ -Wall -W -Werror -c Rational.cc -o Rational.o
    
    test.o: test.cc Rational.h
            g++ -Wall -W -Werror -c test.cc -o test.o
    I appreciate any help and input.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    Code:
    Prog1: main.o Rational.o test.o
            g++ -Wall -W -Werror main.o Rational.o test.o -o Prog1 
    
    
    main.o: main.cc Rational.h
            g++ -Wall -W -Werror -c main.cc 
    
    Rational.o: Rational.cc Rational.h
            g++ -Wall -W -Werror -c Rational.cc
    
    test.o: test.cc Rational.h
            g++ -Wall -W -Werror -c test.cc

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    69
    You might like to use variables at the top of the file so you don't have to change everything in every line. Just makes neater code.

    Example:

    Code:
    CFLAGS=-W -Wall -ggdb `sdl-config --cflags`
    LIBS=-lm `sdl-config --libs`
    OBJS=main.o particle.o background.o resources.o
    CC=g++
    
    default:
    	@echo 'Plese check the variables at the top of the Makefile, then run make program.'
    
    clean:
    	rm -f program $(OBJS)
    	rm -f *~
    
    program:	$(OBJS)
    	$(CC) $(CFLAGS) $(OBJS) -o program $(LIBS)
    
    main.o:	 main.cpp gamedefs.h
    	$(CC) $(CFLAGS) -c main.cpp
    
    particle.o: particle.cpp particle.h gamedefs.h
    	$(CC) $(CFLAGS) -c particle.cpp
    
    background.o: background.cpp background.h gamedefs.h
    	$(CC) $(CFLAGS) -c background.cpp
    
    resources.o: resources.cpp resources.h gamedefs.h
    	$(CC) $(CFLAGS) -c resources.cpp
    That's hopefully helpful. Sorry if it isn't. I know that three modules isn't anything big, but later on, this would save a lot of time.
    D. Olson
    The Mandrake eXPerience
    Battle Pong

    IDE: kate 2.0
    Compiler: gcc 3.2
    Graphics/Input/Net: SDL 1.2.5 (pdf)
    3D Audio: OpenAL (pdf)


    I am a signature virus. Please add me to your signature so that I may multiply

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  2. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

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