2011-07-17 27 views
1

我正在編譯一個包含> 500個類的大型項目。編譯VS 2010之後沒有問題。當使用G ++ Windows下(代碼::塊/ Netbeans的)的代碼不會與下面的錯誤編譯:h和hpp問題,包括的錯誤順序

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文件中,b在某些* .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 

請告知:

  • 其頭/包含策略適用於這樣一個大型項目。
  • 如何查找包含錯誤順序的標題(如果可能的話)
  • 如何重新組織此項目以避免上述問題。

更新的結果:

謝謝大家的有益的建議。

對不起,我完全錯了。一個錯誤實際上是在相對路徑包含字符..(雙點)

重寫所有include指令後,一切正常。

+5

循環依賴永遠不會產生錯誤消息,如'致命錯誤:../../exception/ErrorOverflow.h:沒有這樣的文件或目錄',編譯器明確告訴你它找不到該文件,無論是不在該路徑上,或路徑不正確。 –

+0

路徑存在,它是正確的。檢查路徑的正確性是錯誤的。 – Johnas

+1

您不應該依賴以特定順序包含的頭文件。該錯誤消息不告訴你你的想法是什麼。 –

回答

3

However, this file exists in the specified path

不,它沒有。

雖然你是對的,循環包容會導致一些誤導性的錯誤信息,但這不是其中之一。

有一點要記住的是,列入路徑的分辨率爲實現定義(2003年:12.8/1),這可能是爲什麼你正在穿過工具鏈,看到的不一致。相對路徑的使用特別好奇。簡化源樹和包含路徑,這個問題將消失。

+0

對不起,我完全錯了。一個錯誤實際上是在包含字符的相對路徑中。(雙點)。謝謝你的幫助。 – Johnas

+0

@Johnas:沒問題。讓這成爲你的教訓。 :P –

+0

是的,這是:-))) – Johnas