LNK2019:rapidjson 出现“无法解析的外部符号”

2023-12-03

我有一个 Visual C++ 项目,其中添加了rapidjson 库,经过测试可以正常工作。但是当我添加一个rapidjson::Document嵌套类的类型抛出一个LNK2019当我尝试编译时出错。该项目是一个创建DLL的动态库。

这是我的定义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);
};

这是错误:

错误 LNK1120:1 个未解析的外部

错误 LNK2019:无法解析的外部符号“私有:__thiscall rapidjson::GenericValue,类rapidjson::MemoryPoolAllocator >::GenericValue,类rapidjson::MemoryPoolAllocator >(类rapidjson::GenericValue,类rapidjson::MemoryPoolAllocator > const &)”(? ?0?$GenericValue@U?$UTF8@D@rapidjson@@V?$MemoryPoolAllocator@VCrtAllocator@rapidjson@@@2@@rapidjson@@AAE@ABV01@@Z) 在函数“public: __thiscall rapidjson:: 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)

当我评论注释行时,错误消失了这是问题所在在代码中。如您所见,使用test变量在coreBD类不会导致错误。类型变量的存在rapidjson::Document在嵌套类中会导致显示错误;我用不用它并不重要。

可能是什么问题呢?


EDIT:

收集到的新信息。

当我在父类中使用嵌套类时,就会出现问题,但仅在return的一个方法。换句话说:我可以创造一切rapidjson::Document类型作为成员变量,我可以在中创建一个方法coreBD类与类型jsonObj,我可以实例化jsonObj在该方法内部,但我无法返回类型的值jsonObj如果班级jsonObj has a 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
}

EDIT:

新问题继续解决这个问题:执行rapidjson的Document对象的副本


查看错误似乎该函数返回jsonObj正在执行某种复制或移动构造作为返回值的一部分,并且底层类可能通过将这些构造函数设为私有成员来不允许这样做。

有些类的设计要求禁止复制或赋值,以防止内存泄漏,或者因为对象是单例类型对象并且只允许对象的一个​​版本。

看着这个rapidjson 的文档关于移动语义的部分有一个可能相关的注释。看起来他们正在阻止复制以提高性能。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

LNK2019:rapidjson 出现“无法解析的外部符号” 的相关文章

随机推荐