为什么在复制rapidjson::Document时出现链接器错误而不是编译错误
Why linker error but not compile error when copying rapidjson::Document?
rapidjson::Document
将结果复制到链接错误:
错误5错误LNK2019:未解析的外部符号"private:__thiscall rapidjson::GenericValue,class rapidjson::MemoryPoolAllocator>::GenericValue,class rapidjson::MemoryPoolAllocator>const&)"(??0$GenericValue@U$UTF8@D@rapidjson@@V$MemoryPoolAllocator@VCrtAllocator@rapidjson@@@2@@rapidjson@@AAE@ABV01@@Z) 在函数"public:__thiscall rapidjson::GenericDocument,class rapidjson::MemoryPoolAllocator>:GenericDocument,class rapidijson::MemoryPoolAllocator>const&)"中引用(??0$GenericDocument@U$UTF8@D@rapidjson@@V$MemoryPoolAllocator@VCrtAllocator@rapidjson@@@2@@rapidjson@@QAE@ABV01@@Z) C:\Layer.obj
我看到rapidjson::Document
是rapidjson::GenericValue
的子代它没有复制构造函数:
//! Copy constructor is not permitted.
private:
GenericValue(const GenericValue& rhs);
我想知道为什么没有编译器错误而是链接器错误?C++试图做什么?
我使用MVC 2013和rapidjson 0.11。这里还有类似的线程:
- LNK2019:";未解析的外部符号";使用rapidjson
- Rapidjson无法复制`Rapidjson::Document`
您已经部分回答了自己的问题:
//! Copy constructor is not permitted.
private:
GenericValue(const GenericValue& rhs);
所有类都有一个隐式复制构造函数:http://en.cppreference.com/w/cpp/language/copy_constructor#Implicitly-解密_副本_结构
此代码的作者试图通过在没有定义的情况下声明隐式复制构造函数来禁用它。通过声明,此代码可以进行编译。如果没有定义,它就无法链接,因此您可以看到自己的错误。
更具体地说,您看到的错误消息翻译如下:"GenericDocument类的隐式复制构造函数正在调用GenericValue类的显式复制构造函数。GenericValue中的复制构造函数是声明的,但没有定义。"您看到的文本以其自身的方式更具体,但显然更难阅读。
在您的代码中(可能是使用rapidjson的代码),存在对GenericDocument的复制构造函数的意外或故意调用,这给您带来了整个问题。在我的例子中,我将GenericDocument作为参数传递到函数中。如果你在做同样的事情,你应该通过引用传递文档,这样它就不会被复制。
该错误表示有一个函数已声明,但尚未实现。因此,您必须拥有somes.h,这些somes.h声明了一些函数,但在Rapidjson的任何地方都没有实现。
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- std::is_base_of表示ctor编译错误
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- Qt5:使用QCommandLineParser类时出现奇怪的编译错误
- Qt Cmake 错误编译"GuiSupportQt not found"
- Opengl 精度转换错误编译错误 E0415
- 库将ARM架构错误编译为架构X64
- RT 音频 Mac 错误 g++ 编译错误
- 错误编译Boost.log
- 错误编译QT创建者 / QT窗口小部件示例
- 错误编译MIPS32
- Visual Studio 2013 中的错误(编译和运行代码)
- 链接错误编译qt项目在visual 2010
- 无法用模板错误编译nsgmls
- 奇怪的错误.编译失败
- 如果有人调用c++中的方法,则强制错误(编译时)
- 来自autoconf测试的错误编译命令
- 时间限制超出错误C++编译
- SFML 2.3 和 CodeBlocks 错误编译