0

For an project I want to use the nice paho.mqtt.cpp SDK and have to use it with the old msvc10. The paho.mqtt.cpp uses c+11 extensions massively so I had to modify a lot of source code to get it working with the msvc10 compiler. Must of the stuff could be replaced by boost and I am now able to compile and link the library itself.

When I try to use this modified paho.mqtt.cpp-msvc10-library in other projects i always get linking errors. They look like:

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

and some more of the same sort...

The same is happening when I try to build the delivered examples in the paho.mqtt.cpp SDK.

Does anybody has any Ideas? All the source is available at https://github.com/eclipse/paho.mqtt.cpp

It might be a similar case as in: Why am I getting unresolved externals? but I am not able the find the missing template in case...

I'm on the way to fix it on my own...the problem are the move and copy operators in c+11. The default operators were deleted by my conversion but I forgot to implement them by my own:

For example: Copy operator before:

buffer_ref& operator=(const buffer_ref& rhs)= default

For c+0x we have to implement it by our own:

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;
}

or the move operator in c+11

buffer_ref& operator=(buffer_ref&& rhs) == default   

and our own implementation:

buffer_ref& operator=(buffer_ref&& rhs)
{
    //added moving by spiesra
    if (this != &rhs)
    {
        data_.reset();
        data_ = rhs.ptr();
        rhs.reset();
    }
    return *this;
}

Are my own implemantations are correct?

spiesra
  • 1
  • 1
  • I'll have a look in case it indeed is subtle. There _might_ be an error in the example. Which **exact** example is this about? – sehe Mar 09 '18 at 20:06
  • It is the case with all the examples. The lines above are from the example "async_consume". The fault is not in the example itself (all of them are working with vc14). The error occurs because of my modifications to make them working with vc10. The main things were: - using boost::shared ptr instead of std::shared_ptr - using boost::chrono instead of std::chrono - using typedefs instead of "using" - removing constexpr - not using initializer lists - using boost::async instead of std::async – spiesra Mar 10 '18 at 20:03
  • Does the GitHub link to your modifications.could you share them? – sehe Mar 10 '18 at 20:18
  • see updated question.. – spiesra Mar 12 '18 at 08:23

0 Answers0