New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linker error when passing tuple to object constructor #636
Comments
@sztomi , std::tuple is mapped to ARRAY. ARRAY requires msgpack::zone. So, you can use msgpack::object with msgpack::zone as follows: I think that compile error is better than link error, but so far, it makes link error. |
Can I use |
To shed some light on what I'm trying to do: This is a function that produces a template <typename... Types>
inline msgpack::unpacked make_unpacked(Types... items) {
auto obj = std::make_tuple(items...);
msgpack::sbuffer buf;
msgpack::pack(buf, obj);
return msgpack::unpack(buf.data(), buf.size());
}
// called as:
auto o = make_unpacked(3, 42, "foo", "bar"); This used to work with older versions, but now that I'm upgrading, I'm getting a linker error. How can I safely make an |
I think that your code should work. |
You are right. Sorry, linker errors are confusing sometimes. My actual error:
And the code that uses it: auto o = make_unpacked(3, 42, "foo", "bar");
response r(std::move(o));
And that constructor: using response_type =
std::tuple<uint32_t, uint32_t, msgpack::object, msgpack::object>;
response::response(msgpack::object_handle o) : response() {
response_type r;
o.get().convert(r);
id_ = std::get<1>(r);
auto &&error_obj = std::get<2>(r);
if (error_obj != msgpack::type::nil_t()) {
error_ = std::make_shared<msgpack::object_handle>();
error_->set(msgpack::clone(error_obj).get());
}
result_ = std::make_shared<msgpack::object_handle>(
std::get<3>(r), std::move(o.zone()));
} When upgrading, I had to change Any clue what could cause the linker error? The make_unpacked function did not change. |
I don't understand the code above. Could you show me a minimal and complete code that reproduces the error? If #include <iostream>
#include <tuple>
#include <msgpack.hpp>
int main() {
msgpack::object obj(std::make_tuple(2, "hello", 3.4));
std::cout << obj << "\n";
return 0;
} is so, you can use zone as I mentioned. |
I had a similar issue when trying to create a msgpack::object with a Struct for which I had an adaptor. My initialization was initially like: After adding the zone argument, like so
it worked! I had a similar linker error to sztomi which made debugging it really difficult. Of course from the documentation for msgpack::object it is clear that a zone must be used with a complex object type (since we are not using a msgpack::object_handle and thus must be responsible for the memory management). Perhaps this can be investigated further on the topic of issuing a better compiler error? |
Using the latest release (2.1.5), consider the following code:
This code compiles, but does not link:
If I change the first line to
msgpack::object obj(123);
it compiles and links correctly. I would expect the tuple to also link correctly.OS, compiler info:
The text was updated successfully, but these errors were encountered: