IrrlichtDevice *device 'Unknown Identifier' error

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Scionwest
Posts: 15
Joined: Sun Jul 30, 2006 4:01 am

IrrlichtDevice *device 'Unknown Identifier' error

Post by Scionwest »

I'm at a complete loss here. I've been running through the examples included with the engine and I've been making changes to them as I needed for my game but when I compile the game I get 23 error messages saying that the 'device' (an IrrlichtDevice declared variable) is an unknown identifier. The following is my list of errors.

c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\DX9\Irrlicht\Game\RPG\RPG.h(38): error C2040: 'device' : 'irr::IrrlichtDevice *' differs in levels of indirection from ''unknown-type''
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\DX9\Irrlicht\Game\RPG\mnuMain.h(27): error C2065: 'device' : undeclared identifier
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\DX9\Irrlicht\Game\RPG\mnuMain.h(27): error C2227: left of '->getGUIEnvironment' must point to class/struct/union
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(17): error C3861: 'device': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(20): error C2227: left of '->setWindowCaption' must point to class/struct/union
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(20): error C3861: 'device': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(23): error C2228: left of '.getVideoDriver' must have class/struct/union type
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(23): error C3861: 'device': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(25): error C2227: left of '->getSceneManager' must point to class/struct/union
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(25): error C3861: 'device': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(27): error C2227: left of '->getGUIEnvironment' must point to class/struct/union
type is ''unknown-type''
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(27): error C3861: 'device': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(33): error C2227: left of '->run' must point to class/struct/union
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(33): error C3861: 'device': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(33): fatal error C1903: unable to recover from previous error(s); stopping compilation


And the following is all of my code.

rpg.cpp

Code: Select all

#include "RPG.h"

int main()
{
		device = createDevice( video::EDT_DIRECT3D9, dimension2d<s32>(1024, 768), 32, true, true, true, 0 );

	device->setWindowCaption(L"RPG DEBUG");

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guiEnv = device->getGUIEnvironment();

	guiEnv->addStaticText(L"Welcome to RPG!", rect<int>(10,10,10,10), true);

	//Rendering loop is executed here
	while ( device->run() )
	{
		/*
			Everything gets drawn between the beginscene() and endscene()
		*/
		driver->beginScene(true, true, SColor(255,155,50,120) );

		smgr->drawAll();
		guiEnv->drawAll();

		driver->endScene();
	}

	device->drop();

	return 0;
}
rpg.h

Code: Select all

#ifndef RPG_H
#define RPG_H

//Headers
#include <Irrlicht.h>
#include <iostream>

//Game headers
#include "mnuMain.h"

//Name spaces to use
//Irrlicht Engine
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

//Microsofts
using namespace std;

//libraries
#pragma comment(lib, "Irrlicht.lib")

//Definitions
#define gameName "RPG DEBUG"

extern IrrlichtDevice *device;

#endif
and finally my menu code I was starting...
mnuMain.h

Code: Select all

#include "RPG.h"

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

class mnuMainEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
		if ( event.EventType = EET_GUI_EVENT)
		{
			s32 id = event.GUIEvent.Caller->getID();
			IGUIEnvironment* env = device->getGUIEnvironment();
		}

		return false;
	}

};
The code was working fine until I moved the IrrlichtDevice variable from the rpg.cpp to the rpg.h file when I started working on mnuMain.h. Once I moved it the code would no longer compile. I don't understand why that would be a problem. I'm sure I just don't know what it is I'm doing but if anyone has any ideas I would appreciate them!

Thanks.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If I did not miss anything you simply have an extern declaration only. This does not help since an extern only makes the name accessible, but does not create the variable. Put a line 'IrrlichtDevice* device=0;' right below the include statements in front of your main method.
Scionwest
Posts: 15
Joined: Sun Jul 30, 2006 4:01 am

Post by Scionwest »

Thanks for the advice! Okay, if I remove the #include "mnuMain.h" from my RPG.h header and declare the 'device' variable like you said it fixed the problem, but when I add the following line

Code: Select all

#include "mnuMain.h"
to my RPH.h I recieve 16 different errors now.

Code: Select all

c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\DX9\Irrlicht\Game\RPG\mnuMain.h(30): error C2065: 'device' : undeclared identifier
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\DX9\Irrlicht\Game\RPG\mnuMain.h(30): error C2227: left of '->getGUIEnvironment' must point to class/struct/union
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(13): error C2040: 'device' : 'irr::IrrlichtDevice *' differs in levels of indirection from ''unknown-type''
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(19): error C3861: 'device': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(22): error C2227: left of '->setWindowCaption' must point to class/struct/union
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(22): error C3861: 'device': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(25): error C2227: left of '->getVideoDriver' must point to class/struct/union
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(25): error C3861: 'device': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(27): error C2227: left of '->getSceneManager' must point to class/struct/union
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(27): error C3861: 'device': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(29): error C2227: left of '->getGUIEnvironment' must point to class/struct/union
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(29): error C3861: 'device': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(41): error C2227: left of '->run' must point to class/struct/union
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(41): error C3861: 'device': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\Dx9\Irrlicht\Game\Rpg\RPG.cpp(41): fatal error C1903: unable to recover from previous error(s); stopping compilation
c:\Documents and Settings\Administrator.SERVER\My Documents\Visual Studio Projects\c++\DirectX\DX9\Irrlicht\Game\RPG\RPG.h(37): error C2040: 'device' : 'irr::IrrlichtDevice *' differs in levels of indirection from ''unknown-type''
It's something related to the code in the mnuMain.h header and it's pretty much copied and pasted from the examples included with the engine. The following is my updated code.

rpg.cpp

Code: Select all

#include "RPG.h"

IrrlichtDevice *device = 0;

int main()
{
	device = createDevice( video::EDT_DIRECT3D9, dimension2d<s32>(1024, 768), 32, true, true, true, 0 );

	device->setWindowCaption(L"RPG DEBUG");
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guiEnv = device->getGUIEnvironment();

	guiEnv->addStaticText(L"Welcome to RPG!", rect<int>(10,10,10,10), true);

	scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");scene::ISceneNode* node = 0;

	if (mesh)    node = smgr->addOctTreeSceneNode(mesh->getMesh(0));
 

	//Rendering loop is executed here
	while ( device->run() )
	{
		/*
			Everything gets drawn between the beginscene() and endscene()
		*/
		driver->beginScene(true, true, SColor(255,155,50,120) );

		smgr->drawAll();
		guiEnv->drawAll();

		driver->endScene();
	}

	device->drop();

	return 0;
}
rpg.h

Code: Select all

#ifndef RPG_H
#define RPG_H

//Headers
#include <Irrlicht.h>
#include <iostream>

#include "mnuMain.h"

//Name spaces to use
//Irrlicht Engine
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

//Microsofts
using namespace std;

//libraries
#pragma comment(lib, "Irrlicht.lib")

//Definitions
#define gameName "RPG DEBUG"

extern IrrlichtDevice *device;

#endif
mnuMain.h

Code: Select all

#ifndef MNUMAIN_H
#define MNUMAIN_H

#include "RPG.h"

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

class mnuMainEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
		if ( event.EventType = EET_GUI_EVENT)
		{
			s32 id = event.GUIEvent.Caller->getID();
			IGUIEnvironment* env = device->getGUIEnvironment();
		}

		return false;
	}

};

#endif
I don't know where to go from here. I thought once I declared the variable as extern in my header and re-declared it in my main source file that I could access it through the whole project. I'm not sure if that's correct.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Three things:
1. Buy a good book on C++
2. Your device in RPG.cpp is a definition, device in RPG.h is a declaration. You must have a declaration of a name before its use, and you must have exactly one definition of the variable in your whole program.
3. Move your declaration up in front of the menu-include (such that you have a declaration before device is used) or even better add a declaration to the menu include
This solution will work, but it's not really good. Global variables are evil by default, and your code structure and several dclarations won't make it any better. So better learn structuring your code with simpler examples (and plain C++, no libraries, maybe some STL) and then proceed with Irrlicht.
Post Reply