Johnas
Johnas

Reputation: 1283

h and hpp problem, wrong order of including

I am compiling a large project containing >500 classes. After compiling VS 2010 there have been no problems. When using g++ (Code:: Blocks / Netbeans) under Windows the code will not compile with the following error:

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

However, this file exists in the specified path. Linux version works correctly. Character / or \ in the path does not matter (tested).

If I change order of included files, the above mentioned error disappears and a similar error appears elsewhere in the code...

I think that somewhere in the code there is a cyclic dependency or wrong order of included files.

File structure:

1) .cpp file

#include "file.h"

2) .h file

#ifndef file_H
#define file_H

template <typename T>
class Class 
{
};

#include "file.hpp"
#endif

3) .hpp file

#ifndef file_HPP
#define file_HPP

#include "../../somefile.h"

template <typename T>
class Class 
{

};

#endif

Most of header files *.h are included in *.hpp files, but in some *.h files there is a need for including another *.h file. A short and simplified example illustrating rounding on/off of the result:

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 );
};

Some class Position: method gives round on / round off results

#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

Please advise:


UPDATED RESULTS:

Thank you all for your helpful advice.

I am sorry, I was completely wrong. A bug was actually in relative path containing characters .. (double dot)

After rewriting all include directives is everything OK.

Upvotes: 1

Views: 1758

Answers (1)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385224

However, this file exists in the specified path

No, it does not.

Although you're right in that cyclic inclusion can lead to some misleading error messages, this is not one of them.

One thing to bear in mind is that the resolution of inclusion paths is implementation-defined (2003:12.8/1), which may be why you're seeing inconsistency across toolchains. The use of relative paths is particularly curious. Simplify your source tree and inclusion paths, and this problem will go away.

Upvotes: 3

Related Questions