3

There are two problems I run into occasionally. One is compile time assertions and the other is a header file being included in multiple places in weird ways (this is not my code so I cannot fix it by not including it in weird ways. Even if I tried, it would take too many hours/days as it is deeply embedded), e.g.:

class Foo
{
public:
#include "VariableDeclarations.h" // Some file that has all the variables that need to be declared
                                       // which is also included by several other classes in the same way
};

The above code is a simplication of what I am currently dealing with. Of course, the class Foo is doing other things as well.

Now if I add another variable declaration to the header in this case, and the file Class Foo is in does not know about the type, I will get a compile error. To fix it, I include the necessary headers. Problem is, all the compiler tells me is "undeclared identifier" and the file name comes up as VariableDeclarations.h. I would like to know which file included the declarations and consequently did not know about the type that I just added.

Similar thing happens with compile time assertions. I have no indication as to which line/file caused the error. It just gives me the error (e.g. in Eigen math library, I was experiencing this a lot).

Samaursa
  • 16,527
  • 21
  • 89
  • 160
  • 1
    Why not just inherit from a class containing the variables? – Puppy Jun 16 '11 at 18:26
  • @DeadMG: Like I said, that code was not written by me and the header is being used elsewhere and used in various different macros i.e. too deeply embedded. And if I don't include the type in the header, then a class elsewhere, where the header is being used, does not know about the type. I can put the declaration in every single class that must know about it, but that is probably why this was used in the first place, to automate the process. Assume that I cannot change the code (I have given a very simplified ver. of what is actually going on and why they have included the headers like that) – Samaursa Jun 16 '11 at 18:51

2 Answers2

3

In g++, you can use the verbose option, -v. For intel, the same flag -v should work. For MSVC there is a project option you can tweak somewhere in one of the build settings: How can I make Visual Studio's build be very verbose?

Community
  • 1
  • 1
Mikola
  • 9,176
  • 2
  • 34
  • 41
  • Well, I gave it a try. Was taking too long or Visual Studio stopped responding. So I gave it a try on one source file (although that defeats the purpose in this case, I simply want to know what caused the error not what is generating the error) and the file that Visual Studio spit out is an absolute nightmare to go through. There has to be a better way, what with compile time asserts being the norm for template based libraries. – Samaursa Jun 16 '11 at 19:07
1

The preprocessor pound sign (#) has to be the first symbol on the line for it to be processed, and the trailing ; shouldn't be there either:

class Foo
{
public:
#    include "VariableDeclarations.h"; // Some file that has all the variables that need to be declared
                                       // which is also included by several other classes in the same way
};

Also, both GCC and MSVC have a switch to only run the preprocessor and show you the generated file. That's an excellent tool to debug this kind of stuff.

Blindy
  • 65,249
  • 10
  • 91
  • 131