Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make / gcc cryptic error 2: how to have more information?

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?

like image 903
Gui13 Avatar asked Mar 22 '11 10:03

Gui13


People also ask

What causes linker errors?

Linker errors occur when the linker is trying to put all the pieces of a program together to create an executable, and one or more pieces are missing. Typically, this can happen when an object file or libraries can't be found by the linker.

What does E flag do in GCC?

It tells GCC to stop after the preprocessing stage. Details in the link.

What is GCC error?

Errors report problems that make it impossible to compile your program. GCC reports errors with the source file name and line number where the problem is apparent. Warnings report other unusual conditions in your code that may indicate a problem, although compilation can (and does) proceed.

What is compiler error?

Compilation error refers to a state when a compiler fails to compile a piece of computer program source code, either due to errors in the code, or, more unusually, due to errors in the compiler itself. A compilation error message often helps programmers debugging the source code.


2 Answers

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.

like image 137
Gui13 Avatar answered Sep 18 '22 13:09

Gui13


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.

like image 20
Steve-o Avatar answered Sep 18 '22 13:09

Steve-o