Studying Computer Science on Unix platform is ussually fun expect days when you get stuck.
And life get tough, this is one of my tough days.
To make life easier with my c++ programming I wanted to use the make tool under unix.
I have 5 fieles :
- student.h
- studgrp.h depend on student.h
- demo.cc depend on studgrp.h
- studgrp.cc depend on studgrp.h
- student.cc depend on studgrp.h

So using emacs I typed this small script

record: demo.o studgrp.o student.o
	g++ demo.o studgrp.o sudent.o -o record

studgrp.o: studrgp.h studrgp.cc
	g++ -c studrgp.cc

student.o: studgrp.h student.cc
	g++ -c student.cc

demo.o: studrgp.h demo.cc
	g++ -c demo.cc

And i got this error message

make record
make: *** No rule to make target `studrgp.h', needed by `demo.o'.  Stop.

I think the proble is with student.h because this file is not checked for any changes durring dewelopment of my work. Basic notes from my tutor says this about using make tool:

  • if you change a header, any .cc file that depends on that header must be recompiled
  • if you change a .cc file, that must be recompiled

But what about the relationship between studgrp.h and student.h?
Any suggestions?

Recommended Answers

All 7 Replies

You may want to check the man pages for make, or google a tutorial.

Come wiht good sugestion or do not reply topic please. I couldn't find anything useful on net and Unix man hold nice list of information but not examples, that why I asked people here......

<< plonk >>

Well, today is an good day for me, because I found what is wrong with this code!!!


I have 5 fieles :
- student.h
- studgrp.h depend on student.h
- demo.cc depend on studgrp.h
- studgrp.cc depend on studgrp.h
- student.cc depend on studgrp.h

So using emacs I typed this small script

record: demo.o studgrp.o student.o
	g++ demo.o studgrp.o sudent.o -o record

studgrp.o: studrgp.h studrgp.cc
	g++ -c studrgp.cc

student.o: studgrp.h student.cc
	g++ -c student.cc

demo.o: studrgp.h demo.cc
	g++ -c demo.cc

and what was wrong

record: demo.o studgrp.o student.o
	g++ demo.o studgrp.o student.o -o record

studgrp.o: student.h studgrp.h studgrp.cc
	g++ -c studgrp.cc

student.o: student.h studgrp.h student.cc
	g++ -c student.cc

demo.o: student.h studgrp.h demo.cc
	g++ -c demo.cc

I made mistake in spelling ( I do them, English is not my first language an time to time is hard to concetrate)
As you can see I made an addition to the code, this will check if any changes been done on student.h, if yes everything will be compiled again in one go.

I'm not sure you need list the .h files in the makefile. I think that if the .cc's include the .h's, then it should handle it automatically..

Yes it will handle automaticaly, but the purpose of all this is also to run a check on "h" files see if any changes been done with them. If yes, you have to compile everything again. If you exlud them "make" will not detect it and will not compile for you, so you are still running on old datas!!!!!!!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.