Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MinGW and "declaration does not declare anything"

I'm working on converting a Linux project of mine to compile on Windows using MinGW. It compiles and runs just fine on Linux, but when I attempt to compile it with MinGW it bombs out with the following error message:

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

I'm kind of baffled why this is happening, because

  1. I'm using the same version of g++ (4.4) on both Linux and Windows (via MinGW).
  2. The contents of camera.h is absurdly simple.

Here's the code. It's choking on lines 11 and 12 where float near; and float far; are defined.

#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 both Dirk and mingos, that was exactly the problem!

like image 515
Bob Somers Avatar asked Dec 04 '25 21:12

Bob Somers


2 Answers

Edit If you happen to include windef.h (either directly or indirectly), you will find

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

there. I think, that this is the culprit.

Try

#undef near
#undef far

before your class definition.

like image 54
Dirk Avatar answered Dec 08 '25 14:12

Dirk


Try giving them different names, like

float my_near;
float my_far;

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

like image 22
mingos Avatar answered Dec 08 '25 15:12

mingos