C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-18-2002, 01:20 PM   #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.
-dcx- is offline   Reply With Quote
Old 11-18-2002, 01:33 PM   #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
Captain Penguin is offline   Reply With Quote
Old 11-18-2002, 11:15 PM   #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
DOlson is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 04:02 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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