MinGW and "declaration declare nothing"

I am working on converting my Linux project to compile on Windows using MinGW. It compiles and works fine on Linux, but when I try to compile it with MinGW, it gives me the following error:

camera.h:11: error: declaration does not declare anything
camera.h:12: error: declaration does not declare anything

      

I'm a little puzzled as to why this is happening because

  • I am using the same g ++ (4.4) version for Linux and Windows (via MinGW).
  • The contents of the .h camera are absurdly simple.

Here is the code. It chokes on lines 11 and 12 where float near;

and are defined float far;

.

#include "Vector.h"

#ifndef _CAMERA_H_
#define _CAMERA_H_

class Camera{
public:
  Vector eye;
  Vector lookAt;
  float fov;
  float near;
  float far;
};

#endif

      

Thanks for your help.

EDIT: Thanks to both Dirk and mingos, that was exactly the problem!

+2


a source to share


3 answers


Try giving them different names like

float my_near;
float my_far;

      



I remember that Borland used the words "near" and "far" as keywords (my 1992 Turbo C had them, back in the MS-DOS era). Dunno if this is the case with gcc, but you can always try that.

+3


a source


Edit If you've included windef.h

(directly or indirectly) you will find

#define FAR
#define far
#define NEAR
#define near

      

there. I think this is the culprit.



Try

#undef near
#undef far

      

before defining your class.

+3


a source


In <windef.h>

you will find the following lines:

#define NEAR
#define near

      

Simple answer: you can't have #undef

them because they are part of the Windows headers (_WINDEF_H will still be defined even if you do #undef

these definitions, so it won't be re-enabled if you try #include <windef.h>

again, let alone if you #undef _WINDEF_H

before use #include <windef.h>

after defining your class, you will end up with duplicate definitions for things like RECT, LONG, PROC, etc.), so the only other solution is to change the variable names.

+1


a source







All Articles