반응형

#ifdef EXPORTRULE 
#define MYDLL __declspec(dllexport) 
#else 
#define MYDLL __declspec(dllimport) 
#endif 

이 같은 매크로를 이용해서 DLL 클래스를 작성하였고 

코드:
//--- "myclass.h" ---
class MYDLL CMyClass
{
private:
   CMyClass() {}
   ~CMyClass() {}
 
public:
   static const int SEVEN = 7;
   static const float PI;
};
 
//--- "myclass.cpp" ---
#include "myclass.h"
const float CMyClass::PI = 3.14f;
 
//--- "main.cpp" ---
#include "myclass.h"
int main()
{
   printf("%d", CMyClass::SEVEN); // OK
   printf("%f", CMyClass::PI); // LNK2001
}


위와 같이 컴파일 할 경우 CMyClass::PI에 대해서 LNK2001 에러가 발생합니다. 
static const int 같은 경우는 헤더에서 초기화 및 링크가 잘 되는데 
static const float의 경우 LNK2001 에러가 발생합니다. 

이런 경우 함수를 사용하거나 define 혹은 전역 변수를 쓸 수 밖에 없는지 
고수님들의 의견을 듣고 싶습니다. 
감사합니다.

 

 

 

static const int는 컴파일 단에서 인라인으로 처리 가능한데요 

int 이외의 것들은 그렇지 못하기 때문에 static 변수를 dll로 노출 시키지 못하는 환경 때문에 링크 에러에 거릴겁니다

 

 

반응형

+ Recent posts