本文介绍了LNK2019:“未解析的外部符号”与rapidjson的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个Visual C + +项目,其中我添加了rapidjson库,测试是否正常工作。但是当我添加一个,则 jsonObj 成员变量声明。 例如,这个新创建的方法: { string json ={error:null,message:None,errorMessage:MoreNone}; jsonObj b(json); return b; //如果我返回一个带有rapidjson :: Document的嵌套类,它会失败。返回NULL工作} EDIT : 新问题继续解决:执行快速json的Document对象的副本 解决方案看看错误,看起来函数返回 jsonObj 正在做一些类型的复制或移动构造作为返回值的一部分,底层类不允许这可能通过使那些构造函数的私有成员。 有些类的设计要求禁止复制或赋值以防止内存泄漏,或者因为对象是单例类型对象,并且只允许对象的一个​​版本。 查看此 rapidjson 在可能相关的Move语义的部分中有一条注释。看起来他们正在阻止复制以提高性能。 I have a Visual C++ Project in which I added the rapidjson library, which is tested to be working properly. But when I add a rapidjson::Document type to the nested class is throwing a LNK2019 error when I try to compile. The project is a dynamic library to create a DLL.This 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 classclass 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: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. The mere existence of the variable of type rapidjson::Document in the nested class causes de error to show; 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. 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.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 解决方案 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.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. It looks like they are preventing a Copy in order to improve performance. 这篇关于LNK2019:“未解析的外部符号”与rapidjson的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-15 23:42
查看更多