json: How to resolve " undefined reference to `std::__throw_bad_cast()'"

  • What is the issue you have?

I can compile well on ESP8266’s xtensa_gcc compiler version5.1.0, however when I want to receive string by dump() function . It occurs some errors. How to resolve it?

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

First I try this code

json j = {  {"pi", 3.141}, {"happy", true}, {"name", "testtest"}, 
                    {"nothing", nullptr}, { "answer", { {"everything", 42} } },
                    {"list", {1, 0, 2}}, { "object", { {"currency", "USD"}, {"value", 42.99} } } };

Serial.println((float) j["pi"],3);     // print to Serial Monitor

The result can print well on Serial Monitor --> 3.141
However when I want to dump like the following.

std::string dump_string =  j.dump();

It occurs error like this

libstdc++.a(ostream-inst.o): In function `std::ostream& std::ostream::_M_insert<long>(long)':
libstdc++-v3/include/ostream:544: undefined reference to `std::__throw_bad_cast()'
libstdc++.a(wlocale-inst.o): In function `std::ctype<wchar_t> const& std::use_facet<std::ctype<wchar_t> >(std::locale const&)':
libstdc++-v3/include/bits/locale_facets_nonio.tcc:1173: undefined reference to `std::__throw_bad_cast()'
...

How to resolve "undefined reference to `std::__throw_bad_cast()’ " error ?

Thank you.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (12 by maintainers)

Most upvoted comments

I’ve already tried , but std::__throw_bad_cast() errors still occur.