简体   繁体   English

LNK2019:带有rapidjson的“未解析的外部符号”

[英]LNK2019: “Unresolved external symbol” with rapidjson

I have a Visual C++ Project in which I added the rapidjson library, which is tested to be working properly. 我有一个Visual C ++项目,在其中添加了Rapidjson库,该库经测试可以正常工作。 But when I add a rapidjson::Document type to the nested class is throwing a LNK2019 error when I try to compile. 但是,当我尝试向嵌套类添加rapidjson::Document类型时,会抛出LNK2019错误。 The project is a dynamic library to create a DLL. 该项目是用于创建DLL的动态库。

This are the definitions in my main.h : 这是我的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 the error: 这是错误:

error LNK1120: 1 unresolved externals 错误LNK1120:1个未解决的外部

error LNK2019: 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) referenced in function "public: __thiscall rapidjson::GenericDocument,class rapidjson::MemoryPoolAllocator >::GenericDocument,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) 错误LNK2019:无法解析的外部符号“私有:__thiscall Rapidjson :: GenericValue,class Rapidjson :: MemoryPoolAllocator> :: GenericValue,class Rapidjson :: MemoryPoolAllocator>(class Rapidjson :: GenericValue,class Rapidjson :: MemoryPoolAllocator> const&)”(?在函数“ public:__thiscall Rapidjson:”中引用的0($ GenericValue @ U?$ UTF8 @ D @ rapidjson @@ V?$ MemoryPoolAllocator @ VCrtAllocator @ rapidjson @@@ 2 @@ rapidjson @@ AAE @ ABV01 @@ Z) GenericDocument,类别RapidJSON :: MemoryPoolAllocator> :: GenericDocument,类别Rapidjson :: MemoryPoolAllocator>(类别Rapidjson :: GenericDocument,类别Rapidjson :: MemoryPoolAllocator> const&)“(?? 0?$ GenericDocument @ U?$ UTF8 @ D @ rapidjson @@ V'$ @ MemoryPoolAllocator @ VCrtAllocator @@@ rapidjson 2 @@ rapidjson @@ QAE @ ABV01 @@ Z)

The error disappears when I comment the line commented with HERE IS THE PROBLEM in the code. 当我在代码中用“ 这里是问题”注释掉的行时,错误消失了。 As you can see, the use of the test variable in the coreBD class causes no error. 如您所见,在coreBD类中使用test变量coreBD引起任何错误。 The mere existence of the variable of type rapidjson::Document in the nested class causes de error to show; 嵌套类中仅存在rapidjson::Document类型的变量会导致显示错误。 it doesn't matter if I use it or not. 是否使用它都没关系。

What could be the problem? 可能是什么问题呢?


EDIT : 编辑

New information gathered. 收集了新信息。

The problem appears when I use the nested class inside the parent one, but only in the return of a method. 当我在父类中使用嵌套类时出现问题,但仅在return方法时出现。 In other words: I can create everything with rapidjson::Document type as a member variable, I can create a method in coreBD class with type jsonObj , I can instantiate jsonObj inside that methods, but I cannot return a value of type jsonObj if the class jsonObj has a rapidjson::Document member variable declared. 换句话说:我可以使用rapidjson::Document类型作为成员变量来创建所有内容,可以在coreBD类中创建类型为jsonObj方法, 可以在该方法内部实例化jsonObj但是如果不能,则无法返回类型为jsonObj的值 jsonObjjsonObj了一个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 : 编辑

New question continuing solving this: Perform a copy of Document object of rapidjson 继续解决此问题的新问题: 执行rapidjson的Document对象的副本

Looking at the error it appears that the function returning the jsonObj is doing some kind of a copy or move construction as a part of returning the value and the underlying classes do not allow this probably by making those constructors private members. 查看错误,看来返回jsonObj的函数正在做某种复制或移动构造,作为返回值的一部分,而底层类可能不允许这些构造函数成为私有成员,从而不允许这样做。

There are classes whose design requires that a copy or assignment is prohibited in order to prevent memory leaks or because the objects are singleton type objects and only one version of the object is allowed. 有些类的设计要求禁止复制或分配,以防止内存泄漏,或者因为对象是单例类型的对象,并且只允许该对象的一个​​版本。

Looking at this documentation on rapidjson there is a note in the section on Move semantics that may be pertinent. 查看关于rapidjson的文档,在“移动语义”部分可能有相关注释。 It looks like they are preventing a Copy in order to improve performance. 看来他们在阻止复制以提高性能。

jsonObj doesn't have copy constructor and it can't have any copy constructor since Document's copy constructor is disabled in rapidjson. jsonObj没有复制构造函数,也没有任何复制构造函数,因为在RapidJSON中禁用了Document的复制构造函数。 Try to hold pointer to document instead, something like this : 尝试改为保持指向文档的指针,如下所示:

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

Or pass document( jsonObj ) from outside to: 或从外部将文档( jsonObj )传递给:

jsonObj query(string sSQL);

For example: 例如:

query(string sSQL, jsonObj & out_obj)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM