Unix Programming - tool to find .h dependencies in C++

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > March 2007 > tool to find .h dependencies in C++





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author tool to find .h dependencies in C++
Rares Vernica

2007-03-27, 1:18 am

Hi,

I am working at a C++ project with many .h files. In the Makefile, for
each .cc file I need to list the .h files on which the .cc file depends
on so that it is recompiled whenever any of those changes.

What tool would you recommended for finding .h dependencies for a given
..cc file?

Thanks a lot,
Ray
Alexander Pazdnikov

2007-03-27, 1:18 am

Hi, Ray


$(CPP) $(INC_DIR) -MM -MF "$(DEPDIR)/$*.dep" -c $<

g++ -I./includes -I./headers -MM -MF myclass.dep -c myclass.cpp

It's really easy to make target in Makefile to produce dependecies
files for each *.cpp
As example

..PHONY : dep
DEPS=$(SRCS:.cpp=.dep)

dep: $(DEPS)

%.dep : %.cpp
$(CPP) $(INC_DIR) -MM -MF "$(DEPDIR)/$*.dep" -c $<

And include your depences files into Makefile

sinclude $(DEPDIR)/*.dep

Good Day
--
Alexander Pazdnikov

Logan Shaw

2007-03-27, 1:18 am

Rares Vernica wrote:
> I am working at a C++ project with many .h files. In the Makefile, for
> each .cc file I need to list the .h files on which the .cc file depends
> on so that it is recompiled whenever any of those changes.
>
> What tool would you recommended for finding .h dependencies for a given
> .cc file?


How about :

$ whatis makedepend
makedepend (1x) - create dependencies in makefiles
$

I believe it's originally intended for C programs, but this is really
a C preprocessor matter, not a compiler issue, so I think in this case
what works for C will work for C++. Hmm, except that makedepend may
have difficulty with stuff like "#include <iostream>" (i.e. the missing
".h").

- Logan
Ralf Fassel

2007-03-27, 7:16 am

* Logan Shaw <lshaw-usenet@austin.rr.com>
| Hmm, except that makedepend may have difficulty with stuff like
| "#include <iostream>" (i.e. the missing ".h").

There is no missing .h, the file is indeed called 'iostream', without
any extension. But makedepend has indeed problems locating all of the
c++ include files, you need a bunch of -I directives. Better let the
compiler do the job...

R'
Rares Vernica

2007-03-27, 1:19 pm

Ralf Fassel wrote:
> * Logan Shaw <lshaw-usenet@austin.rr.com>
> | Hmm, except that makedepend may have difficulty with stuff like
> | "#include <iostream>" (i.e. the missing ".h").
>
> There is no missing .h, the file is indeed called 'iostream', without
> any extension. But makedepend has indeed problems locating all of the
> c++ include files, you need a bunch of -I directives. Better let the
> compiler do the job...
>
> R'


Thanks a lot folks,

Ray
Walt Fles

2007-03-28, 1:18 pm

On Mar 27, 4:21 am, Ralf Fassel <ralf...@gmx.de> wrote:
> * Logan Shaw <lshaw-use...@austin.rr.com>
> | Hmm, except that makedepend may have difficulty with stuff like
> | "#include <iostream>" (i.e. the missing ".h").
>
> There is no missing .h, the file is indeed called 'iostream', without
> any extension. But makedepend has indeed problems locating all of the
> c++ include files, you need a bunch of -I directives. Better let the
> compiler do the job...
>
> R'


Or use a make engine that supports finding these dependencies and
utilizes the dependency tree properly,
like Lucent's nmake, or the Open Source version from AT&T:
http://www.research.att.com/sw/download/

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com