Multiply defined symbols when using optional_support
metiscus opened this issue · comments
Take this pseudocode example.
a.h:
#pragma once
#include <optional>
#include <staticjson/staticjson.hpp>
struct a
{
int value;
std::optional<float> f;
void staticjson_init(staticjson::ObjectHandler *h);
};
a.cpp:
#include <staticjson/optional_support.hpp>
void a::staticjson_init(staticjson::ObjectHandler *h)
{
h->add_property("value", &value);
h->add_property("f", &f, Flags::Optional);
}
If you end up including optional_support.hpp in several files you will get a multiply defined symbol, but it would appear that it is required to include the header to get support for optional.
src/physicalcomponent.o:(.data.rel.ro.local+0x0): multiple definition of `staticjson::nonpublic::nullopt'
src/object.o:(.data.rel.ro.local+0x0): first defined here
A potential fix is to make nullopt static in the template. I will submit a matching pull request.
Thanks for the bug report. I fixed it in 30c4e8d with a using declaration. It is better than static
as it does not add symbols at all, only alias.
I knew there had to be a way to fix the issue without resorting to static but I didn't have time to figure out the right way. Thanks for the speedy fixup :) Awesome thing you've got here.