1

I am trying to create a C++ plugin (through a .dll) for Unity in order to use an haptic device. I am using Visual Studio Community 2017. I already wrote some code but I am not able to compile it because when i try i get "undeclared identifier" errors for the classes i defined in the functions prototype, as you can find below. My biggest concern relies on the fact that IntelliSense correctly recognizes everything as what it is meant to be, so i have no idea of what may be the problem. I am aware that it might be something very simple and stupid, but i am completely stuck here.

Righ now i have a header which is something like:

#ifndef PLUGIN_HEADER
#define PLUGIN_HEADER
#define APIENTRY __declspec(dllexport)

#include <Windows.h>
#include <iostream>
#include <map>
/* a bunch of other includes */
#include "RenderableClass.h"
#include "AuxClass.h"
extern "C" {
    /*ERROR COMES UP IN THE FOLLOWING LINE*/
APIENTRY void PluginInitialization(AuxClass* aux); 
APIENTRY void PluginCleanUp(AuxClass* aux); 
};

#endif

and a source that looks like this

#include "header.h"

APIENTRY void PluginInitialization(AuxClass* aux) 
{
    /* Initialization of the haptic device */
}

APIENTRY void PluginCleanUp(AuxClass* aux)
{
    /* memory release */
}

AuxClass and RenderableObject are basically just a bunch of attributes:

AuxClass.h:

#ifndef AUX_CLASS
#define AUX_CLASS

#include "header.h"
class AuxClass
{
public:
    /*Attrtibutes*/
    HHD m_hhd;
    HHLRC m_hhlrc;
    std::map<int, RenderableClass> m_objects;

    AuxClass();
    ~AuxClass();
};

#endif // !AUX_CLASS

AuxClass.cpp is exactly this:

#include "AuxClass.h"
AuxClass::AuxClass(){  }
AuxClass::~AuxClass(){  }

Moreover, RenderableCLass.h and RenderableClass.cpp are respectively:

#ifndef RENDERABLE_CLASS
#define RENDERABLE_CLASS

#include "header.h"

class RenderableClass
{
public:

    /*Attributes*/
    int* m_triangles;
    float* m_vertices;
    int m_id;
    /*other attributes*/

    /*Methods*/
    RenderableClass();
    ~RenderableClass();
};

and

#include "RenderableClass.h"
RenderableClass::RenderableClass(){   }
RenderableClass::~RenderableClass(){   }

The error i get is the following:

Error   C2065   'AuxClass': undeclared identifier

and it is in the header, in the prototype of the first function, were i put the comment. () Does someone have some idea for a possible solution? Thanks in advance

Leocrsp
  • 11
  • 2
  • 2
    You appear to have circular includes. `header.h` includes `AuxClass.h`, which in turn includes `header.h`. Similarly with `RenderableCLass.h` – Igor Tandetnik Nov 08 '18 at 16:12
  • I'm confused. Is `PluginInitialization` supposed to be using `APIENTRY` or `LEOAPI`, or are you talking about two different functions? is that why you declare one after including the header file that declares the other? – Tim Randall Nov 08 '18 at 16:18
  • Please provide a MVCE. – Walter Nov 08 '18 at 16:22
  • Btw, the empty constructor and destructor will be auto generated if you simply not define & declare them. – Walter Nov 08 '18 at 16:24
  • You should ensure that each header includes everything it immediately needs (i.e. `AuxClass.h` includes `RenderableCLass.h`, `` etc, and `header.h` only includes `AuxClass.h`) but not more and consequently avoid circular includes. – Walter Nov 08 '18 at 16:28
  • Thanks guys, circular headers was the problem. You're awesome! Plus, I've just edited the question in order not to confuse anyone with the macros, since i changed the names before posting to get more readable ones and i messed them up a little – Leocrsp Nov 08 '18 at 16:51

0 Answers0