Home c++ Error LNK2001 unresolved external symbol

Error LNK2001 unresolved external symbol [duplicate]

Author

Date

Category

I can’t understand what the mistake is, correct it, maybe I’m doing something wrong somewhere. If you remove StartClass (); , then the program writes that it is not clear what s is equal to. I use irrlicht , but it doesn’t matter in this situation.

StartGame.h

#ifndef _STARTGAME_H
 #define _STARTGAME_H
 using namespace irr;
 using namespace gui;
 using namespace core;
 using namespace scene;
 using namespace video;
 using namespace io;
class StartClass
   {
   public:
   void Start ();
   StartClass ();
   IrrlichtDevice * device;
   video :: IVideoDriver * driver;
   scene :: ISceneManager * smgr;
   IGUIEnvironment * guienv;
   scene :: ICameraSceneNode * camera;
   };
   #endif

StartGame.cpp

# include & lt; irrlicht.h & gt;
#include & lt; iostream & gt;
#include & lt; sys / stat.h & gt;
#include "AILoad.h"
#include & lt; cmath & gt;
#include "StartGame.h"
using namespace irr;
using namespace gui;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
void StartClass :: Start ()
{
StartClass s;
s.device = createDevice (video :: EDT_OPENGL, core :: dimension2d & lt; u32 & gt; (800,600));
s.driver = s.device- & gt; getVideoDriver ();
s.smgr = s.device- & gt; getSceneManager ();
s.guienv = s.device- & gt; getGUIEnvironment ();
s.camera = s.smgr- & gt; addCameraSceneNodeFPS ();
}

main.cpp

# include "main.h"
#include & lt; irrlicht.h & gt;
#include & lt; iostream & gt;
#include & lt; sys / stat.h & gt;
#include "AILoad.h"
#include & lt; cmath & gt;
#include "StartGame.h"
using namespace irr;
using namespace gui;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
#ifdef _MSC_VER
#pragma comment (lib, "Irrlicht.lib")
#endif
int main ()
{
  StartClass s;
  s.camera- & gt; setPosition (core :: vector3df (0,0,0));
  s.camera- & gt; setFarValue (10000.0f);
}

Error:

alt text


Answer 1, authority 100%

The error says almost everything you need. You have declared but not defined the constructor of the StartClass class.

In addition, the Start method looks suspicious, since it does not work with the object itself (this method is inside the class, see?), but creates a temporary object, initializes its fields and immediately kills him.

I think you need a constructor like this:

StartClass :: StartClass ()
{
  device = createDevice (video :: EDT_OPENGL, core :: dimension2d & lt; u32 & gt; (800,600));
  driver = device- & gt; getVideoDriver ();
  smgr = device- & gt; getSceneManager ();
  guienv = device- & gt; getGUIEnvironment ();
  camera = smgr- & gt; addCameraSceneNodeFPS ();
}
Previous articleWhat is the size_t type?
Next articleKeyword `auto`

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions