msgpack / msgpack-c

MessagePack implementation for C and C++ / msgpack.org[C/C++]
Other
3.02k stars 878 forks source link

MSGPACK_DEFINE_MAP error #977

Closed nobody93 closed 3 years ago

nobody93 commented 3 years ago

Hi,

I have a weird error to build following file, if I change MSGPACK_DEFINE_MAP(s, m, r, p, o, t, i) to MSGPACK_DEFINE_MAP(s, m, r, p, i), the error was gone, what was it going on?

class ProvisionRequest { public: ........... MSGPACK_DEFINE_MAP(s, m, r, p, o, t, i)

private: uint64_t s; // Serial number uint16_t m; // message ID uint16_t r; // Rate uint16_t p; // Port number uint16_t o; // OEM ID uint16_t t; // Protocol type ID std::string i; // IP address };

Build caused following error:

In file included from /usr/include/msgpack/object.hpp:15:0, from /usr/include/msgpack.hpp:10, from ProvisionRequest.hpp:19, from ProvisionRequest.cpp:18: /usr/include/msgpack/v1/object.hpp: In instantiation of ‘const msgpack::v2::object& msgpack::v1::adaptor::convert<T, Enabler>::operator()(const msgpack::v2::object&, T&) const [with T = const msgpack::v2::object; Enabler = void]’: /usr/include/msgpack/v1/adaptor/adaptor_base.hpp:58:42: required from ‘typename std::enable_if<(! std::is_array< >::value), const msgpack::v2::object&>::type msgpack::v1::operator>>(const msgpack::v2::object&, T&) [with T = const msgpack::v2::object; typename std::enable_if<(! std::is_array< >::value), const msgpack::v2::object&>::type = const msgpack::v2::object&]’ /usr/include/msgpack/v1/object.hpp:545:24: required from ‘typename std::enable_if<((! std::is_array< >::value) && (! std::is_pointer<_Tp>::value)), T&>::type msgpack::v1::object::convert(T&) const [with T = const msgpack::v2::object; typename std::enable_if<((! std::is_array< >::value) && (! std::is_pointer<_Tp>::value)), T&>::type = const msgpack::v2::object&]’ /usr/include/msgpack/v2/object_fwd.hpp:60:56: required from ‘T& msgpack::v2::object::convert(T&) const [with T = const msgpack::v2::object]’ /usr/include/msgpack/v1/adaptor/detail/cpp11_define_map.hpp:34:43: recursively required from ‘static void msgpack::v1::type::define_map_imp<Tuple, N>::unpack(const msgpack::v2::object&, const Tuple&, const std::map<std::cxx11::basic_string, const msgpack::v2::object>&) [with Tuple = std::tuple<const char (&)[2], long unsigned int&, const char (&)[2], short unsigned int&, const char (&)[2], unsigned char&, const char (&)[2], unsigned char&, const char (&)[2], const msgpack::v2::object&, const char (&)[2], unsigned char&, const char (&)[2], std::cxx11::basic_string<char, std::char_traits, std::allocator >&>; long unsigned int N = 12]’ /usr/include/msgpack/v1/adaptor/detail/cpp11_define_map.hpp:34:43: required from ‘static void msgpack::v1::type::define_map_imp<Tuple, N>::unpack(const msgpack::v2::object&, const Tuple&, const std::map<std::cxx11::basic_string, const msgpack::v2::object>&) [with Tuple = std::tuple<const char (&)[2], long unsigned int&, const char (&)[2], short unsigned int&, const char (&)[2], unsigned char&, const char (&)[2], unsigned char&, const char (&)[2], const msgpack::v2::object&, const char (&)[2], unsigned char&, const char (&)[2], std::cxx11::basic_string<char, std::char_traits, std::allocator >&>; long unsigned int N = 14]’ /usr/include/msgpack/v1/adaptor/detail/cpp11_define_map.hpp:80:70: required from ‘void msgpack::v1::type::define_map::msgpack_unpack(const msgpack::v2::object&) const [with Args = {const char [2], long unsigned int, const char [2], short unsigned int, const char [2], unsigned char, const char [2], unsigned char, const char [2], const msgpack::v2::object, const char [2], unsigned char, const char [2], std::__cxx11::basic_string<char, std::char_traits, std::allocator >}]’ /home/jupiter/data/Repository/sa_platform_library/Source/SolarAnalytics/Platform/Library/Message/InverterProvisionRequest.hpp:46:5: required from here /usr/include/msgpack/v1/object.hpp:209:7: error: ‘const struct msgpack::v2::object’ has no member named ‘msgpack_unpack’ v.msgpack_unpack(o.convert()); ^~~~ /usr/lib/gbx/MakefilesV2/rules.mk:27: recipe for target 'Build/Source/SolarAnalytics/Platform/Library/Message/InverterProvisionRequest.o' failed

redboltz commented 3 years ago

Could you post a Minimal, Reproducible Example? https://stackoverflow.com/help/minimal-reproducible-example

nobody93 commented 3 years ago

Hi redboltz,

Thanks for your response, here are attached source files in tarball code.tar.gz

redboltz commented 3 years ago

It is not complete. Please read again https://stackoverflow.com/help/minimal-reproducible-example carefully.

prog.cc:7:52: error: use of undeclared identifier 'Common'
ProvisionRequest::ProvisionRequest() : MessageBase(Common::Definition::MessageType::INVERTER_OEM_PROVISION), s(0), m(0), r(0), p(0), o(0), t(0) {
                                                   ^
1 error generated.

You need to remove more codes that aren't related to the issue. It should be a single cpp file If you can. And please add int main() `. And please don't attach tar ball. Please write the code in the comment using github comment formatting like as follows:

#include <msgpack.hpp>

int main() {
}
nobody93 commented 3 years ago

Hi redboltz, I think there is a weird bug in the macro, the error is gone when I changed uint16_t o; to uint16_t e;

Thank you.

redboltz commented 3 years ago

It seems that your problem is disappeared. So I close the issue. This is a Minimal, Reproducible Example https://wandbox.org/permlink/KYjXDPA3sdD1F0G3 Please use this in the future issue report.