1

This is similar to Warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated. However, the OP was trying to compile header files. In my case, I'm trying to generate dependencies:

$ git diff
diff --git a/GNUmakefile b/GNUmakefile
index 791ef05..ce48a59 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -175,6 +176,11 @@ LIBIMPORTOBJS = $(LIBOBJS:.o=.import.o)
 TESTIMPORTOBJS = $(TESTOBJS:.o=.import.o)
 DLLTESTOBJS = dlltest.dllonly.o

+-include GNUmakefile.deps
+
+GNUmakefile.deps:
+       $(CXX) $(CXXFLAGS) -MM *.h *.cpp > GNUmakefile.deps
+

How do I use CXX to build dependencies while avoiding the Clang warning?

Community
  • 1
  • 1
jww
  • 97,681
  • 90
  • 411
  • 885
  • 1
    Even when doing `-MM`, you probably don't really want to do that with .h files - if they are not included in your .cpp files, they (most likely) don't need to be in the dependencies... – Mats Petersson Jul 18 '15 at 00:39
  • @Mats - Thanks. What about inline functions and static implementations? Will I get expected results? – jww Jul 18 '15 at 00:42
  • -MM list gives you a dependency listing based on what is included by what file - so assuming you don't later on try to compile .h files, and only care about making object files from .cpp files, you should be fine just using *.cpp in the deps generation. For inline functions to be useful from a header file, they will need to be compiled in a .cpp file, right? – Mats Petersson Jul 18 '15 at 00:44
  • Well, how would `make` (or whatever tool you use) know what dependencies there are? That's exactly what `-MM` is for. Listing the include files that are included by a particular source file. Something, somewhere needs to know/understand/follow all the header files included by a particular source file... There is no shortcut, something, somewhere needs to have that list.... – Mats Petersson Jul 18 '15 at 00:50
  • Thanks Mats. That begs the question, is there some tool to verify that project includes in source files are complete? (Sorry to be a help vampire. I cannot ask this question on SO). – jww Jul 18 '15 at 00:54
  • I'm not aware of such a tool - is there any reason you don't trust `-MM` - so far I've not found it to fail, but I've only been using it for about 10-12 years, not 50... – Mats Petersson Jul 18 '15 at 00:57
  • *" is there any reason you don't trust -MM..."* - I don't think `-MM` is the problem. If the `*.cpp` file is missing a `*.h` file, then I don't believe `-MM` will help. I run into this issue on occasion; see, for example, [Added missing include. Caused compile failure on Android or iOS](https://github.com/weidai11/cryptopp/commit/3e2b437172505b07f8b53fd52265622dddf49fc8). In this case, the compile worked on BSDs, Linux, OS X and Windows. – jww Jul 18 '15 at 01:13
  • Right, that is a different issue, and it's only really solved by compiling your code with all the different variants that you wish to use... No easy way out of that one, I'm afraid :( – Mats Petersson Jul 18 '15 at 10:23
  • Thanks Mats. That's the tool I am looking for to ensure my makefile dependencies are accurate :) – jww Jul 18 '15 at 23:04

1 Answers1

2

The -MM option of the c++ compiler will give a list of all dependencies for the input file. Assuming you actually compile .cpp files (and don't do $(CXX) -c xyz.h or some such) , the dependencies are only needed for your .cpp files. So changing this to:

 $(CXX) $(CXXFLAGS) -MM *.cpp > GNUmakefile.deps

should give all the dependencies you need in GNUmakefile.deps.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227