12

I have this C++ project which compiles using a Makefile, and sometimes when (my guess) there are some missing includes, I get a cryptic "error 2" message and the make process stops.
I suspect the missing includes because this is the third times it happens when I included a non-existent header file.

It looks like this:

---- Build tmp/foo.o ----
---- Build tmp/bar.o ----
---- Build tmp/toto.o ----
---- Build tmp/tata.o ----
make: *** [build_Project] Error 2

This is driving me nuts, because even using verbose commands (where each g++ invocation is showed), I can't see anything.
I expected the guy to throw up some erroneous messages like "can't find header X" or "undefined reference to Y", but there's nothing.

My compiling options for gcc are -O0 -Wall -Werror -Wno-write-strings -fno-rtti -fno-exceptions, if this helps.

Ah, and we use the Makefile trick of including dependencies:

ifneq ($(strip $(DEPENDS)),)
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPENDS)
endif
endif

( see here and here for more information )

Although this is documented stuff, I suspect my problem has something to do with this dependencies inclusion.

If you already stumbled on this issue, feel free to comment on this...

Thanks in advance.

edit: Okay, after a bit of playing, suppressing the - in front of -include $(DEPENDS) gives me some more info (the makefile does stop on the missing included file).

make[1]: *** No rule to make target « foo.h », necessary for « tmp/bar.d ». Stop.

Now the drawback is that when I launch make for the first time, I get a missing bar.d file message for each dependency file that should be included (which was why we put the - in the first place). Any solution?

Community
  • 1
  • 1
Gui13
  • 12,993
  • 17
  • 57
  • 104
  • 1
    I think we need to see more of the makefile e.g. how you call gcc- and I tend to show the command compiling for this sort of reason – mmmmmm Mar 22 '11 at 11:01
  • 1
    Some makefiles switch off the fancy output if you set a variable. `automake`, for instance, will show commands if you run `make V=1`, also try `make VERBOSE=1`, or inspect the `Makefile` to get a better idea. – Jack Kelly Mar 22 '11 at 11:57

2 Answers2

5

Ok my edit solved the problem: placing a dash - in front of include hides the error messages coming from the dependency generation.

Note for later: don't try to outsmart Make.

Gui13
  • 12,993
  • 17
  • 57
  • 104
2

It's a bespoke Makefile, possibly via some tool like CMake that is hiding the compiler output similar to this:

gcc -o a.out a.c 2>&1 > /dev/null

If you don't know what is happening it sounds like a good idea to revisit the build system completely, try starting anew.

Steve-o
  • 12,678
  • 2
  • 41
  • 60
  • Nope, I did write the makefile, but maybe passed on some tricky side-effect. The compilation line doesn't contain such `2>&1 > /dev/null` so it couldn't be that. – Gui13 Mar 22 '11 at 12:50
  • 1
    This is very outdated, but I think you should have said something like, 'if this is a smaller or newer project, it can really helpful to try starting anew'. Simply suggesting starting anew, without qualification, does not take account of the fact that large existing build systems can break after tool updates, or when coming up to speed setting up the build system for the first time. – MikeBeaton Feb 13 '23 at 08:18