static 멤버 변수를 dllexport 하려면?

프로그래밍 일반에 관한 포럼입니다.

Moderator: 류광

Locked
비회원

static 멤버 변수를 dllexport 하려면?

Post by 비회원 »

안녕하세요.
개편이 다가온 시점에 질문글을 써서 죄송하네요.

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

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

Code: Select all

//--- "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 혹은 전역 변수를 쓸 수 밖에 없는지
고수님들의 의견을 듣고 싶습니다.
감사합니다.
비회원

Post by 비회원 »

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

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