Hello! :)

I'm trying to achieve an 'engine' of a kind in a DLL project. I have successfully made a DLL that works, but as simple as Hello World.

Now I'm coding a framework into the DLL project, but I'm having some trouble with the singleton function.

Im getting this linker error:

DLLProject.obj : error LNK2001: unresolved external symbol "public: static class MyDLL::Framework * MyDLL::Framework::ofManager" (?ofManager@Framework@MyDLL@@2PAV12@A)

DLLProject.h

namespace MyDLL
{
  class Framework
  {
  public:
    static __declspec(dllexport)  Framework* ofManager;
     Framework();
    ~Framework();
    static __declspec(dllexport) Framework* createManager();
    static __declspec(dllexport) Framework* getSingletonPtr()
    {
      return ofManager;
    };
    ...
  private:
    ...
  };
}

DLLProject.cpp

#include "DLLProject.h"
namespace myDLL
{
  Framework::Framework()
  {
    ofManager = this;
  }
  Framework* Framework::createManager()
  {
    if(ofManager == 0) ofManager = new Framework();
    return ofManager;
  }
  ...

Hope anyone can help, I'm really putting my hair out over this, and hoped that the time invested would not get me asking for help, but oh ;)

No one has a clue?

A pretty fundamental C++ concept at work, here. Whenever you declare a static data member of a class, you must also define it in the cpp file. For this user's example:

__declspec(dllexport) Framework* Framework::ofManager = 0;

It has nothing to do with being a DLL.

The initialisation to zero is not syntactically mandatory, but is sensible in this example.

This thread is 8 months old, lol :)
I learnt this long ago, but thank you anyway I guess.

I know, but just in case someone else comes here from a web search, having the same problem.

That's how I came here, looking for a solution to another problem, largely unrelated, concerning unresolved externals from a DLL, which I have since solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.