我正在編譯一個包含> 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指令後,一切正常。
循環依賴永遠不會產生錯誤消息,如'致命錯誤:../../exception/ErrorOverflow.h:沒有這樣的文件或目錄',編譯器明確告訴你它找不到該文件,無論是不在該路徑上,或路徑不正確。 –
路徑存在,它是正確的。檢查路徑的正確性是錯誤的。 – Johnas
您不應該依賴以特定順序包含的頭文件。該錯誤消息不告訴你你的想法是什麼。 –