2014-03-27 61 views
2

我有一個Visual C++項目,其中添加了rapidjson庫,該庫已經過測試,可以正常工作。但是,當我嘗試編譯時向嵌套類添加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 &)" (??0?$GenericDocument[email protected][email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@[email protected]@@Z)

當我評論的評論線與在這裏的錯誤消失是問題代碼中的。如您所見,在coreBD類中使用test變量不會導致錯誤。在嵌套類中僅僅存在類型爲rapidjson::Document的變量會導致顯示錯誤;不管我是否使用它都沒關係。

可能是什麼問題?


編輯

新的信息收集。

當我在父級內使用嵌套類時,會出現問題,但只在方法的return中使用。換句話說:我可以創建rapidjson::Document類型作爲成員變量,我可以在coreBD類創建一個方法與jsonObj類型的一切,我可以實例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's,正如你所看到的,這個庫在我的項目的其他部分都能正常工作 – SysDragon

+0

這是一個單獨的解決方案嗎?這意味着您的應用程序的其他工作部分被放置在您項目的不同解決方案中。 – XAMlMAX

回答

1

望着錯誤看來該函數返回作爲回報的一部分,jsonObj正在做某種副本或移動構建這個值和底層類不允許這可能通過使這些構造函數成爲私有成員。

有些類的設計要求禁止複製或賦值以防止內存泄漏,或者因爲對象是單例類型的對象而只允許一個版本的對象。

看看這個documentation on rapidjson在移動語義部分有一個註釋可能是相關的。看起來他們正在阻止複製以提高性能。

+0

看起來像文檔相關的文檔部分缺失。 – SysDragon

+0

@SysDragon,我認爲你是對的,文檔看起來不完整。但是,有一部分標題爲「移動語義」,從頂部開始討論分配,複製和移動的2/3。一般來說,文檔似乎相當簡單。在document.h包含文件中有一個註釋,表示不允許複製構造函數,參見第54行https://code.google.com/p/rapidjson/source/browse/trunk/include/rapidjson/document.h –

+0

這就是我現在有問題。我無法定義de拷貝構造函數,因爲「無法訪問私有成員」。我試圖使用'Document.Accept()'方法,它似乎執行副本:http://stackoverflow.com/a/19604013/1967056 – SysDragon

相關問題