LNK2019:使用rapidjson“未解析的外部符号”

时间:2014-03-27 08:55:15

标签: c++ visual-c++ visual-studio-2012 rapidjson

我有一个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:未解析的外部符号“private:__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)

当我在代码中注释用 HERE IS THE BLBLEM 注释的行时,错误消失了。如您所见,在test类中使用coreBD变量不会导致错误。在嵌套类中仅存在类型rapidjson::Document的变量会导致显示de error;如果我使用它并不重要。

可能是什么问题?


修改

收集了新信息。

当我在父类中使用嵌套类时出现问题,但仅在方法的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

2 个答案:

答案 0 :(得分:1)

看到错误,看起来返回jsonObj的函数正在执行某种复制或移动构造作为返回值的一部分,而基础类不允许这样做可能使这些构造函数变为私有成员。

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

看一下这个documentation on rapidjson,关于Move语义的部分中有一个注释可能是相关的。看起来他们正在阻止复制以提高性能。

答案 1 :(得分:0)

jsonObj没有复制构造函数,也没有任何复制构造函数,因为在RapidJSON中禁用了Document的复制构造函数。尝试保持指向文档的指针,像这样:

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

或将文档(jsonObj)从外部传递到:

jsonObj query(string sSQL);

例如:

query(string sSQL, jsonObj & out_obj)
相关问题