LNK2019: "Unauthorized external character" with fastjson

I have a Visual C ++ project in which I added the rapidjson library, which is checked for proper operation. But when I add the type rapidjson::Document to the nested class, it throws an LNK2019 error when trying to compile. The project is a dynamic library for creating DLLs.

These are the definitions in my 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); }; 

This is mistake:

error LNK1120: 1 unresolved external

LNK2019 error: unresolved external symbol "private: __thiscall rapidjson :: GenericValue, class rapidjson :: MemoryPoolAllocator> :: GenericValue, class rapidjson :: MemoryPoolAllocator> (class rapidjson :: GenericValue, class rapidjson :: MemoryPoolAllocator> const &)" (? 0? $ GenericValue @U? $ UTF8 @D @rapidjson @@ V? $ MemoryPoolAllocator @VCrtAllocator @rapidjson @@@ 2 @@ rapidjson @@ AAE @ ABV01 @@ Z) link to the function "public: __thiscall rapidjson :: GenericDocument , class rapidjson :: MemoryPoolAllocator> :: class rapidjson :: MemoryPoolAllocator> (class rapidjson :: GenericDocument, class rapidjson :: MemoryPoolAllocator> const &) "(? 0? $ GenericDocument @U? $ UTF8 @D @rapidjson @ @V? $ MemoryPoolAllocator @VCrtAllocator @rapidjson @@@ 2 @@ rapidjson @@ QAE @ ABV01 @@ Z)

The error disappears when I comment on the line commented HERE, PROBLEM in the code. As you can see, using the test variable in the coreBD class coreBD not cause errors. The mere existence of a variable of type rapidjson::Document in a nested class causes an error; it doesn’t matter if I use it or not.

What could be the problem?


EDIT

New information collected.

The problem occurs when I use a nested class inside the parent, but only in the return method. In other words: I can create everything with type rapidjson::Document as a member variable, I can create a method in the coreBD class with type jsonObj , I can create an instance of jsonObj inside these methods , but I cannot return a value of type jsonObj if class jsonObj has a declared member variable rapidjson::Document .

For example, this new created method:

 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 } 

EDIT

A new issue that continues to be addressed is: Run a copy of the Document rapidjson object

+2
source share
2 answers

Looking at the error, it seems that the function returning jsonObj is executing some kind of copy or moving the construct as part of the return value, and the base classes do not allow this, possibly by creating these constructors as private members.

There are classes that require that copy or assignment be prohibited to prevent memory leaks or because objects are objects of a singleton type and only one version of the object is allowed.

Looking at the documentation on quickjson , a note can be seen in the section on the semantics of Move. They seem to prevent copying to improve performance.

+1
source

jsonObj does not have a copy constructor and cannot have a copy constructor because the document copy constructor is disabled in rapidjson. Try holding the pointer to the document instead, something like this:

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

Or pass the document ( jsonObj ) from the outside:

 jsonObj query(string sSQL); 

For instance:

 query(string sSQL, jsonObj & out_obj) 
0
source

Source: https://habr.com/ru/post/1443717/


All Articles