简体   繁体   中英

DLL class with a static members

I have an DLL in which I have added a second class which has only static members, but when I try to build this I got linker error:

Error   14  error LNK2001: unresolved external symbol "__declspec(dllimport) private: static double BubblyCore::BubblyTime::delta" (__imp_?delta@BubblyTime@BubblyCore@@0NA)    D:\Projekty\bubbly-engine\BCore\BCore.obj   BCore

And same for second member.

Here is my header:

#ifdef BCOREDLL_EXPORTS
#define BCOREDLL_API __declspec(dllexport) 
#else
#define BCOREDLL_API __declspec(dllimport) 
#endif

#include <..\BDisplay.h>
#include <ctime>
#include <chrono>

typedef std::chrono::time_point<std::chrono::system_clock, std::chrono::system_clock::duration> BChronoTime;

namespace BubblyCore
{
    // This class is exported from the BCOREDll.dll
    class BCOREDLL_API MainBubble
    {
    public:

    private:
        BDisplay* pbDisplay;
        bool isRunning;

    public:
        MainBubble(BDisplay* pbDisplay);
        void Start();
        void Stop();
    private:
        void Run();
        void Render();
        void CleanUp();
    };

    class BCOREDLL_API BubblyTime
    {
    public:
        static BChronoTime bStartTime;
    private:
        static double delta;
    public:
        static long getTime();
        static double getDelta();
        static void setDelta(double sDelta);
    };

}

I am talking specific about BubblyTime. The first one is Ok so far.

Inside one of your .cpp files, add the following lines :

  double BubblyCore::BubblyTime::delta = 0.0;

Declaring static variables in a header file won't be sufficient. You need to declare their real instances in some .cpp files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM