对于一个项目,我想使用漂亮的 paho.mqtt.cpp SDK,并且必须将它与旧的 msvc10 一起使用。paho.mqtt.cpp 大量使用 c+11 扩展,因此我不得不修改大量源代码以使其与 msvc10 编译器一起使用。必须的东西可以用 boost 代替,我现在可以编译和链接库本身。
当我尝试在其他项目中使用这个修改后的 paho.mqtt.cpp-msvc10-library 时,我总是遇到链接错误。他们看起来像:
LNK2019 unresolved external symbol "public: __cdecl mqtt::buffer_ref<char>::buffer_ref<char>(class mqtt::buffer_ref<char> &&)" (??0?$buffer_ref@D@mqtt@@QEAA@$$QEAV01@@Z) referenced in function "class boost::shared_ptr<class mqtt::message> __cdecl boost::make_shared<class mqtt::message,class mqtt::buffer_ref<char>,void const * &,unsigned __int64 &,int &,bool &>(class mqtt::buffer_ref<char> &&,void const * &,unsigned __int64 &,int &,bool &)" (??$make_shared@Vmessage@mqtt@@V?$buffer_ref@D@2@AEAPEBXAEA_KAEAHAEA_N@boost@@YA?AV?$shared_ptr@Vmessage@mqtt@@@0@$$QEAV?$buffer_ref@D@mqtt@@AEAPEBXAEA_KAEAHAEA_N@Z) async_consume
LNK2001 unresolved external symbol "public: __cdecl mqtt::buffer_ref<char>::buffer_ref<char>(void)" (??0?$buffer_ref@D@mqtt@@QEAA@XZ) async_consume
LNK2001 unresolved external symbol "public: class mqtt::buffer_ref<char> & __cdecl mqtt::buffer_ref<char>::operator=(class mqtt::buffer_ref<char> &&)" (??4?$buffer_ref@D@mqtt@@QEAAAEAV01@$$QEAV01@@Z) async_consume
以及更多同类...
当我尝试在 paho.mqtt.cpp SDK 中构建交付的示例时,也会发生同样的情况。
有人有任何想法吗?所有源代码都可以在https://github.com/eclipse/paho.mqtt.cpp获得
这可能是类似的情况: 为什么我得到未解决的外部问题? 但我无法找到丢失的模板以防万一......
我正在自行修复它......问题是c + 11中的移动和复制运算符。我的转换删除了默认运算符,但我忘了自己实现它们:
例如: 复制运算符之前:
buffer_ref& operator=(const buffer_ref& rhs)= default
对于 c+0x 我们必须自己实现:
buffer_ref& operator=(const buffer_ref& rhs)
{
//added copying by spiesra
if (this != &rhs)
{
data_.reset();
data_ = rhs.ptr();
data_.reset(new blob(reinterpret_cast<const value_type*>(rhs.data()), rhs.size()));
}
return *this;
}
或 c+11 中的移动运算符
buffer_ref& operator=(buffer_ref&& rhs) == default
和我们自己的实现:
buffer_ref& operator=(buffer_ref&& rhs)
{
//added moving by spiesra
if (this != &rhs)
{
data_.reset();
data_ = rhs.ptr();
rhs.reset();
}
return *this;
}
我自己的实施是否正确?