redboltz / mqtt_cpp

Boost Software License 1.0
433 stars 107 forks source link

Compile Error In visual studio 2017 #919

Open runner66 opened 2 years ago

runner66 commented 2 years ago

as document said "It requires C++14 and the Boost Libraries 1.67.0 or later.", but when comiple in VS (with boost1.68+cpp14), I get serveal errors. boost_1_68_0\boost\variant\detail\make_variant_list.hpp(40): error C2977: “boost::mpl::list”: boost_1_68_0\boost\variant\detail\make_variant_list.hpp(40): error C2955: “boost::mpl::list”:

Only when I define MQTT_STD_VARIANT with cpp17, I can compile sucess.

redboltz commented 2 years ago

On clang++ (13.0.1) -std=c++14, Boost 1.78.0, MQTT_STD_VARIANT=OFF cmake option (MQTT_STD_VARIANT preprocessor macro is not defined), no errors are reported. C2977 means too many template arguments.

https://github.com/redboltz/mqtt_cpp/blob/f1ebfbfc111bd99b1f131e5f28f7c2b9067947c5/include/mqtt/config.hpp#L12-L29

mqtt_cpp set to the limit list size to 40 if it is not defined.

Those information might help you to analyze the problem.

redboltz commented 2 years ago

Perhaps, insert

#include <mqtt/variant.hpp>

into the top of your source code (cpp file) might solve the error.

If it is solved please let me know the current include information.

runner66 commented 2 years ago

Yes, It works. ths a little weird...

runner66 commented 2 years ago

another puzzle, what's the difference mqtt_cpp-12.0.0 and mqtt_cpp-master? seems code is not absolutly the same

redboltz commented 2 years ago

Yes, It works. ths a little weird...

Oh really, I need your source code (mqtt_cpp include part) to fix the issue. So far, I only know the error code. I cant't fix it.

Maybe https://github.com/redboltz/mqtt_cpp/blob/f1ebfbfc111bd99b1f131e5f28f7c2b9067947c5/include/mqtt/client.hpp#L10 https://github.com/redboltz/mqtt_cpp/blob/f1ebfbfc111bd99b1f131e5f28f7c2b9067947c5/include/mqtt_client_cpp.hpp#L7 are related.

redboltz commented 2 years ago

another puzzle, what's the difference mqtt_cpp-12.0.0 and mqtt_cpp-master? seems code is not absolutly the same

You can compare by yourself https://github.com/redboltz/mqtt_cpp/compare/v12.0.0...master

runner66 commented 2 years ago

Ok, ths. I try to compile the same code in Linux OS with vscode, but get a lot of errors, any tips?

mqtt/will.hpp:47:23: error:enclosing class of constexpr non-static member function ‘mqtt::buffer& mqtt::will::topic()’ is not a literal type constexpr buffer& topic() { ^ mqtt/will.hpp:50:29: error:enclosing class of constexpr non-static member function ‘const mqtt::buffer& mqtt::will::message() const’ is not a literal type constexpr buffer const& message() const { ^ mqtt/will.hpp:53:23: error:enclosing class of constexpr non-static member function ‘mqtt::buffer& mqtt::will::message()’ is not a literal type constexpr buffer& message() { ^ mqtt/will.hpp:56:22: error:enclosing class of constexpr non-static member function ‘mqtt::retain mqtt::will::get_retain() const’ is not a literal type constexpr retain get_retain() const { ^ mqtt/will.hpp:59:19: error:enclosing class of constexpr non-static member function ‘mqtt::qos mqtt::will::get_qos() const’ is not a literal type constexpr qos get_qos() const { ^ mqtt/will.hpp:62:37: error:enclosing class of constexpr non-static member function ‘const properties& mqtt::will::props() const’ is not a literal type constexpr v5::properties const& props() const { ^ mqtt/will.hpp:65:31: error:enclosing class of constexpr non-static member function ‘mqtt::v5::properties& mqtt::will::props()’ is not a literal type constexpr v5::properties& props() {