how should a file containing a class be called in the makefile?

closed account (S8hvC542)
For example, I have three files:

main.cpp
myclass.h
myclass.cpp

-main.cpp #include's myclass.h

Below is the makefile. My problem is that if I change only myclass.cpp, the changes are not pulled in. What am I doing wrong in this build process?

Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CC=g++
LN=$(CC)


mainbin : main myclass.o
	@echo "a test of this stuff"
	@echo "compiling and linking the code"
	$(LN) -o mkfiletest main

main : mkfiletest.cpp
	$(CC) -Wall -c  mkfiletest.cpp

myclass.o : myclass.h myclass.cpp
	$(CC) -Wall -c myclass.h 
	$(CC) -Wall -c myclass.cpp 


I can't be of any help because I know little about makefiles. But if you want to go easy on yourself, you can just use an IDE. Then you don't have to worry about this crap.
What happens if you change

main : mkfiletest.cpp

to

main : mkfiletest.o ?

Additionally, why are you compiling myclass.h ? If that header file is #include 'd in myclass.cpp, there's no need at all for you to be compiling it into an object file.


I'm not sure you need a lot of your makefile; what happens if you just have

mainbin : mkfiletest.o myclass.o ?
Last edited on
closed account (S8hvC542)
If I just have that, make complains that it doesn't know how to create "mkfiletest.o" or "myclass.o".
closed account (S8hvC542)
This tutorial explained it to me:

http://www.cs.umd.edu/class/fall2002/cmsc214/Tutorial/makefile.html

basically, my "main" from above should included a dependency on the h file of the included class.
Topic archived. No new replies allowed.