H和HPP问题,包含顺序错误



我正在编译一个包含>500个类的大型项目。在编译VS 2010之后,没有任何问题。当在Windows下使用g++ (Code:: Blocks/Netbeans)时,代码将无法编译并出现以下错误:

library/source/algorithms/file/../../algorithms/graph/../algebra/../spheredistance
/file.hpp:31:51: fatal error: ../../exception/ErrorOverflow.h: No such file or directory. 
Compilation terminated.

但是,该文件存在于指定的路径中。Linux版本正常。路径中的/或字符无关紧要(已测试)。

如果我改变包含的文件的顺序,上面提到的错误消失,类似的错误出现在代码的其他地方…

我认为在代码的某个地方存在循环依赖或包含的文件顺序错误。

文件结构:1) .cpp文件

#include "file.h"
2) .h文件
#ifndef file_H
#define file_H
template <typename T>
class Class 
{
};
#include "file.hpp"
#endif
3) .hpp文件
#ifndef file_HPP
#define file_HPP
#include "../../somefile.h"
template <typename T>
class Class 
{
};
#endif

大多数头文件*.h都包含在*.hpp文件中,但在一些*.h文件中需要包含另一个*.h文件。一个简短的示例,说明了结果的四舍五入:

Orientation.h
#ifndef Orientation_H
#define Orientation_H

typedef enum
{
    RoundOn, RoundOff
} TRound;

class Orientation
{
    public:
            template <typename T>
            static short getOrientation( const T dx1, const T dy1, const T dx2, const T dy2, const TRound round = RoundOff );
};

一些类的位置:方法给出四舍五入的结果

#include "Orientation.hpp"
Position.hpp
#ifndef Position_H
#define Position_H
#include "../orientation/Orientation.h"  //must be included for Rounding

class Position
{
    public:
            template <typename Point1, typename Point2>
            static unsigned short getPosition ( const Point1 * p, const Point2 * p1, const Point2 * p2, const TRoundType round );
};
#include "Position.hpp"
#endif

请建议:

  • 哪个header/include策略适合这么大的项目。
  • 如何找到包含错误顺序的头(如果可能的话)
  • 如何重组该项目以避免上述问题。

更新结果:

谢谢大家的建议。

对不起,我完全错了。一个bug实际上是在相对路径中包含字符的。(二阶导数)

重写了所有include指令之后,一切都OK了。

但是,这个文件存在于指定的路径

不,它没有。

虽然循环包含会导致一些误导性的错误消息,但这不是其中之一。

要记住的一件事是包含路径的解析是实现定义的(2003:12.8/1),这可能就是为什么您看到跨工具链不一致的原因。相对路径的使用特别奇怪。简化源代码树和包含路径,这个问题就会解决。

最新更新