2

Visual Studioで遊んでいると、理解できないエラーが見つかりました。クラスをエクスポートするDLLを作成しました。別のDLLプロジェクトを作成し、最初のDLLクラスをメンバー変数として使用しようとすると、宣言方法によっては機能しません。

これは最初のDLLクラスです。

class LOCKING_API CCriticalSection {
public:
    CCriticalSection(void);
    ~CCriticalSection(void);
    void Enter(void);
    void Leave(void);
    BOOL TryEnter(void);
private:
    CRITICAL_SECTION CriticalSection;
};

2番目のDLLの場合:

#include "../Locking/Locking.h"

class APPLICATION_API CApplication {
public:
    static CApplication* instance(void);
private:
    CApplication(void);
    static CApplication* pInstance;
    static CCriticalSection CritSect;
};

コンパイルしようとすると、次のエラーが発生します。

Application.obj : error LNK2001: unresolved external symbol "private: static class CCriticalSection CApplication::CritSect" (?CritSect@CApplication@@0VCCriticalSection@@A)
4

1 に答える 1

0

You're probably not initializing the static members of CApplication. In one of your cpp files, have:

CCriticalSection CApplication::CritSect;

(and do the same with pInstance, of course)

Edit:

Another possibility is that you're not linking to the lib file of your first DLL in the project of your second DLL. If that's the case, the compiler sees CCriticalSection's declaration, but the linker can't find its implementation. See .Lib Files as Linker Input.

于 2012-06-18T19:48:52.663 に答える