bakercp / ofxHTTP

A suite of HTTP tools, including clients and servers for openFrameworks.
MIT License
110 stars 37 forks source link

Problem compiling with Xcode 10.2 "could not find from_json() method in T's namespace" #49

Closed michaelbaisch closed 5 years ago

michaelbaisch commented 5 years ago

Hello everyone,

I just updated to Xcode 10.2 and my OF project (of_v0.10.1) using ofXHTTP is suddenly throwing an error:

json.hpp:870:9: Static_assert failed "could not find from_json() method in T's namespace"

It also happens after a freshly build example example_basic_server_file with ProjectGenerator.

The Problem seems to originate from ofxHTTP/libs/ofxHTTP/src/OAuth10Credentials.cpp

In file included from ~/Projects/of_v0.10.1_osx_release/addons/ofxHTTP/libs/ofxHTTP/src/OAuth10Credentials.cpp:8:
In file included from ../../../addons/ofxHTTP/libs/ofxHTTP/include/ofx/HTTP/OAuth10Credentials.h:14:
In file included from ~/Projects/of_v0.10.1_osx_release/addons/ofxHTTP/example_basic_server_file/../../../libs/openFrameworks/utils/ofJson.h:3:
../../../libs/json/include/json.hpp:870:9: error: static_assert failed "could not find from_json() method in T's namespace"
        static_assert(sizeof(BasicJsonType) == 0,
        ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../libs/json/include/json.hpp:879:16: note: in instantiation of function template specialization 'nlohmann::detail::from_json_fn::call<nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer>, std::__1::basic_string_view<char, std::__1::char_traits<char> > >' requested here
        return call(j, val, priority_tag<1> {});
               ^
../../../libs/json/include/json.hpp:926:9: note: in instantiation of function template specialization 'nlohmann::detail::from_json_fn::operator()<nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer>, std::__1::basic_string_view<char, std::__1::char_traits<char> > >' requested here
        ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
        ^
../../../libs/json/include/json.hpp:3237:36: note: in instantiation of function template specialization 'nlohmann::adl_serializer<std::__1::basic_string_view<char, std::__1::char_traits<char> >, void>::from_json<const nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer> &, std::__1::basic_string_view<char, std::__1::char_traits<char> > >' requested here
        JSONSerializer<ValueType>::from_json(*this, ret);
                                   ^
../../../libs/json/include/json.hpp:3495:16: note: in instantiation of function template specialization 'nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer>::get<std::__1::basic_string_view<char, std::__1::char_traits<char> >, std::__1::basic_string_view<char, std::__1::char_traits<char> >, 0>' requested here
        return get<ValueType>();
               ^
In file included from ~/Projects/of_v0.10.1_osx_release/addons/ofxHTTP/libs/ofxHTTP/src/OAuth10Credentials.cpp:8:
In file included from ../../../addons/ofxHTTP/libs/ofxHTTP/include/ofx/HTTP/OAuth10Credentials.h:11:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:875:29: note: in instantiation of function template specialization 'nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer>::operator basic_string_view<std::__1::basic_string_view<char, std::__1::char_traits<char> >, 0>' requested here
        {__self_view __sv = __t; return assign(__sv);}
                            ^
~/Projects/of_v0.10.1_osx_release/addons/ofxHTTP/libs/ofxHTTP/src/OAuth10Credentials.cpp:97:60: note: in instantiation of function template specialization 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=<nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer>, void>' requested here
        if (key == "consumerKey") credentials._consumerKey = value;

Is there a way of quickly fixing it so I can use my project again?

Greetings, Michael

bakercp commented 5 years ago

I'm checking on this. A quick fix would be to step back a few versions using git bisect to see where things went awry.

See below.

bakercp commented 5 years ago

@michaelbaisch Hi there, I loaded everything from scratch (a few osx release 0.10.1) and all addons required for ofxHTTP from their stable branches (though master should work too) and could not reproduce the issue. I have not tested ofxHTTP on (or even installed) Xcode 10.2 because .. well the usual bugs. I have not upgraded to macOS 10.14 for the same reason. I'd try the following in order of my best guess:

  1. Xcode 10.2 may not be playing well with our older packaged version of nlohmann::json. (2.6.1 I think). I would recommend downloading the latest version (https://github.com/nlohmann/json/releases/download/v3.6.1/json.hpp) and replacing the one in your of_v0.10.1_osx_release/libs/json/include/ folder to see if that fixes it. I tested this and it compiled fine on my setup. The next version of oF 0.11.0 will include the latest version 3.6 or 3.61.

  2. If that doesn't work, start fresh with the stable branches of all ofxHTTP addons and try again with the included addon examples. If those work, try it with your own code.

  3. If that doesn't work, revert to Xcode 10.1 and try 2 again.

  4. If that doesn't work, revert to macOS 10.13.6 and try 3.

  5. If none of those work ... I'm really sorry :)

michaelbaisch commented 5 years ago

Just be clear I'm a 100% sure that this is because of Xcode 10.2, I just updated from Xcode 10.1 where everything worked just fine.

Thanks for the quick response, and your first point did work! Thank you!

bakercp commented 5 years ago

Super!

vanderlin commented 5 years ago

updating to the latest version of nlohmann::json worked for me. Is this fixed in the master of OF?

bakercp commented 5 years ago

It's updated in the latest apothecary, but the apothecary submodule isn't updated in the openFrameworks:master I don't think. It will be included in the next release, which should be out soon AFAIK.