Hi Rémi On Fri, Apr 08, 2011 at 02:10:32PM +0200, Rémi Delmas wrote: > Hello, > > I need to compute the file dependencies for C++ source and header > files. Using the -MM option of gcc, here is how I proceed today: > > For example, if I need to get the dependencies for main.cpp and > main.hpp, I would execute : > > >g++ -x c++ -MM -Iincludepath main.cpp main.hpp > main.o: main.cpp main.hpp includepath/include2.hpp > main.o: main.hpp includepath/include2.hpp > > I then parse the output to get my result with minimal effort (I ignore > the .o file, and the remainder of the line is simply the original > source file followed by the list of its dependencies). > > My problem is that the -MM option of gcc is not meant to be used with > header files, and seems to choke on header-only pragmas such as > "#pragma once". I have been looking at an option to ignore pragmas, > with no success. > > Could anyone either provide me with a way to ignore unwanted pragmas, > or else with a idea on how to achieve the desired result? > > Thanks a lot in advance. CC'ing me in the reply would be very much > appreciated. Since this is the first time I post on that list, please > redirect me to a more appropriate list if needed. For me, this works as expected. With the two files: test.cc: #include "a.h" #include "b.h" a.h: #pragma once #include "c.h" I obtain (this is g++ version 4.1.2): > g++ -MM -MG test.cc test.o: test.cc a.h c.h b.h > g++ -MM -MG a.h a.o: a.h c.h which seems to be fine. The "-MG" just assumes missing files to be auto-generated (here: b.h and c.h) Did I misunderstand your problem? Another solution to your problem might be the use of "makedepend", which has nothing to do with gcc (at least to my knowledge), but which is designed to generate such header-dependencies in a most-efficient way (especially if you have really large projects...) Axel