2014-03-27 3 views
2

제대로 작동하는 것으로 테스트 된 rapidjson 라이브러리를 추가 한 Visual C++ 프로젝트가 있습니다. 하지만 rapidjson::Document 유형을 중첩 클래스에 추가하면 컴파일 할 때 LNK2019 오류가 발생합니다. 프로젝트는 DLL을 만드는 동적 라이브러리입니다. LNK2019 : rapidjson과 함께 "확인되지 않은 외부 기호"

main.h의 정의입니다 :

class coreBD { 
string conn; 
string proxy; 
int type; 
Document test; 

enum dataBases { 
    Sqlite, 
    SqlServer, 
    None 
}; 

string queryBD(string sSQL); 
string queryHTTP(string sSQL); 

string httpRequest(string url, string proxy); 

static string getNow(string format); 
static string urlEncode(string url); 
static bool startsWith(string source, string with); 

public: 

enum access { 
    dbConn, 
    HTTPProtocol 
}; 

//Nested class 
class jsonObj { 
    string jsonStr; 
    string message; 
    Document doc; //HERE IS THE PROBLEM 
    bool validMsg; 

public: 
    enum response { 
     FullResponse, 
     SQLResponse 
    }; 

    jsonObj(string json); 
    string getJsonStr(response rType); 
    string getErrorMsg(); 
    bool isValidResponse(); 
}; 

coreBD(string connStr, access connType); 
jsonObj query(string sSQL); 
void setProxy(string proxy); 
}; 

이 오류입니다 : 내가 선이 여기 주석으로 언급 할 때

error LNK1120: 1 unresolved externals

error LNK2019: unresolved external symbol "private: __thiscall rapidjson::GenericValue,class rapidjson::MemoryPoolAllocator >::GenericValue,class rapidjson::MemoryPoolAllocator >(class rapidjson::GenericValue,class rapidjson::MemoryPoolAllocator > const &)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@[email protected]@@Z) referenced in function "public: __thiscall rapidjson::GenericDocument,class rapidjson::MemoryPoolAllocator >::GenericDocument,class rapidjson::MemoryPoolAllocator >(class rapidjson::GenericDocument,class rapidjson::MemoryPoolAllocator > const &)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@[email protected]@@Z)

오류가 사라집니다 문제는 코드에서 보시다시피, test 변수를 coreBD 클래스에 사용하면 오류가 발생하지 않습니다. 중첩 된 클래스에 rapidjson::Document 유형의 변수가 존재하면 오류가 표시됩니다. 내가 사용하는지 여부는 중요하지 않습니다.

무엇이 문제 일 수 있습니까?


편집 :

새로운 정보를 수집.

부모 개체 내부에서 중첩 된 클래스를 사용할 때 문제가 발생하지만 메서드의 return에서만 발생합니다. 즉 : 나는, 내가 형 jsonObjcoreBD 클래스의 방법을 만들 수있는 멤버 변수로 rapidjson::Document 유형으로 모든 것을 만들 수 있습니다, 그 방법 내부 jsonObj, 을 인스턴스화 할 수 있지만 클래스 경우 유형 jsonObj의 값을 반환 할 수 없습니다 jsonObj에는 rapidjson::Document 멤버 변수가 선언되어 있습니다. 예를 들어

이 새로운 생성 방법 :

jsonObj coreBD::testOBJ() 
{ 
    string json = "{error:null, message:None, errorMessage:MoreNone}"; 
    jsonObj b(json); 
    return b; //It fails here if I return a nested class with a rapidjson::Document in it. Returning NULL works 
} 

편집 :

새로운 문제를 계속 해결이 : Perform a copy of Document object of rapidjson

+0

rapidjason의 라이브러리 파일을 프로젝트 속성의 참조로 사용하십시오. –

+0

@Trinity rapidjson은 단지 헤더이며, # include와 함께 프로젝트에 포함되어 있습니다. 당신이 읽을 수있는 한, 라이브러리는 프로젝트의 다른 모든 부분에서 제대로 작동하고 있습니다. – SysDragon

+0

언제든지이 솔루션이 별도의 솔루션입니까? 응용 프로그램의 다른 작업 부분이 프로젝트의 다른 솔루션에 배치된다는 것을 의미합니다. – XAMlMAX

답변

1

오류 보면 함수가 반환하는 것으로 보인다 jsonObj은 일종의 복사본을 만들거나 반환 구성의 일부로 이동합니다. 값을 넣으면 기본 클래스는 생성자를 비공개 멤버로 만들어 허용하지 않습니다.

메모리 누수를 방지하기 위해 또는 객체가 싱글 톤 유형의 객체이고 객체의 한 버전 만 허용되기 때문에 복사 또는 할당이 금지되어야하는 설계가있는 클래스가 있습니다.

documentation on rapidjson을 보면 관련이있을 수있는 의미 이동 섹션이 있습니다. 성능을 향상시키기 위해 복사를 방해하는 것처럼 보입니다.

+0

'Document' 객체에 상대적인 문서의 일부분이 보이지 않는 것 같습니다. – SysDragon

+0

@SysDragon, 나는 당신이 옳다고 생각합니다. 문서가 불완전한 것처럼 보입니다. 그러나 할당, 복사 및 이동에 대해 설명하는 맨 위에서 아래로 내려가는 방법의 약 2/3에 대한 이동 시맨틱 섹션이 있습니다. 일반적으로 문서화는 아주 희박한 것 같습니다. 복사 생성자가 허용되지 않는 document.h include 파일에 주석이 있습니다. 54 행 참조 https://code.google.com/p/rapidjson/source/browse/trunk/include/rapidjson/document.h –

+0

문제가 생겼어. "private 멤버에 액세스 할 수 없으므로"복사 생성자를 정의 할 수 없습니다. 복사를 수행하는 것'Document.Accept()'메서드를 사용하려고합니다 : http://stackoverflow.com/a/19604013/1967056 – SysDragon