You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
json.hpp:8955: multiple definition of function that is not defined twice or more. #804
// This file called "lib.hpp"using json = nlohmann::json;
namespacesomeNS {
someType someFunction(json file) {
// ...
}
}
...Returns this error:
lib.hpp.o: In function `std::iterator_traits<char const*>::iterator_category std::__iterator_category<char const*>(char const* const&)':
json.hpp:8955: multiple definition of `someNS::someFunction(nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>)'
main.cpp.o:lib.hpp:7: first defined here
Activity
nlohmann commentedon Oct 27, 2017
I cannot reproduce this with:
and version 2.1.1.
Running
yields
theodelrieu commentedon Oct 27, 2017
This looks a lot like a missing include guard, do you include
json.hppdirectly or through another of your own header files?nm17 commentedon Oct 27, 2017
@theodelrieu I have included it.
theodelrieu commentedon Oct 27, 2017
Could you paste the contents of
lib.hpp?nm17 commentedon Oct 27, 2017
@theodelrieu
theodelrieu commentedon Oct 27, 2017
I guess this file is included multiple times, try to add a
#pragma onceat the very top of your file, this should work.nm17 commentedon Oct 27, 2017
@theodelrieu Here is the code. The first one was older.
Also it does not work...
theodelrieu commentedon Oct 27, 2017
Oh I didn't realize, it's very simple in fact.
This has nothing to do with this library, you should not define a method in a header, unless:
inline(in your case this doesn't seem very judicious)nm17 commentedon Oct 27, 2017
Thank you!