정의되지 않은 참조 링커 오류가 발생하지만 공유 리소스를 할당하는 SetUpTestCase()
메서드가있는 테스트 사례를 작성 중입니다.SetUpTestCase 정적 변수를 사용하여 Google 테스트 정의되지 않은 참조
class ParsingEventsTest: public ::testing::Test {
protected:
static xml eventXml;
static void SetUpTestCase() {
ManagedObjectManagerSingleton::GET_SINGLETON().initializeTestEnvironment(PATH_TO_FILE);
eventXml= *ManagerSingleton::GET_SINGLETON().parse(PATH_TO_INPUT_FILES);
}
virtual void SetUp() {}
virtual void TearDown() {}
};
이 원인이 :
../test/ParsingEventsTest.o: In function `ParsingEventsTest::SetUpTestCase()':
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xa1): undefined reference to `ParsingEventsTest::eventXml'
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xb0): undefined reference to `ParsingEventsTest::eventXml'
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xbd): undefined reference to `ParsingEventsTest::eventXml'
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xc2): undefined reference to `ParsingEventsTest::eventXml'
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xce): undefined reference to `ParsingEventsTest::eventXml'
../test/ParsingEventsTest.o:ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xdd): more undefined references to `ParsingEventsTest::eventXml' follow
collect2: ld returned 1 exit status
편집 :이 또한 아주 간단한 예를 들어, 작동
을 int 할당
class ParsingEventsTest: public ::testing::Test {
protected:
static int *x;
static void SetUpTestCase() {
x = new int [30];
}
static void TearDownTestCase() {
delete [] x;
}
virtual void SetUp() {}
virtual void TearDown() {}
};
'eventXml' 정의를 볼 수 없습니다. 어디서 뒀어? –
@TadeuszKopec 'xml' -'static xml eventXml;' – Patryk
의 코드에 있습니다. 내 클래스에 정적 멤버가있는 경우 왜 내 C++ 프로그램 링크가 연결되지 않습니까?] (http://stackoverflow.com/questions)/1976983/why-wont-my-c-program-link-when-my-class-has-static-members) –