开发者

Trace the steps the compiler took that resulted in the error

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 inclu开发者_如何学JAVAded 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).


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜