.dll ファイルについて
//SWC.h
#ifndef _SWC_
# define _SWC_
# define SWC_CALL __declspec(dllexport)
#else
# define SWC_CALL __declspec(dllimport)
#endif
namespace SWC
{
struct SWC_CALL Mouse
{
//interface
};
class SWC_CALL SWC_Base : public someClass1, public someClass2
{
static Mouse mouse;
};
//other classes goes here...
}
//SWC_Base.cpp
namespace SWC
{
Mouse SWC_Base::mouse; //needed, to compile
//other SWC_Base function definition
}
.exeファイルについて
でstatic struct Mouse mouse
定義した でSWC_Base
リンク エラーが発生する
このファイルで再定義することで問題を解決します
//main.cpp
#include "SWC.h"
#pragma comment (lib, "..\\SWC")
SWC::Mouse SWC::SWC_Base::mouse; //<- why do I need to redefine it again?
int main()
{
//...
return 0;
}
.cpp ファイルで SWC_Base::mouse を既に定義していますが、それを使用するファイルで再度定義する必要があるのはなぜですか? 私の.dllプロジェクトは静的変数で成長しているため、これ以上の問題が発生する可能性があることはわかっています。