bblanchon / ArduinoJson

šŸ“Ÿ JSON library for Arduino and embedded C++. Simple and efficient.
https://arduinojson.org
MIT License
6.7k stars 1.12k forks source link

error: std::string is not declared #1967

Closed margaretselzer closed 1 year ago

margaretselzer commented 1 year ago

Description I have a rather complex Arduino project where I use ArduinoJson. When using version 6.19.4 the code compiled without any problems. We have updated now to ArduinoJson 6.21.3 and get build errors. The first build error is "/ArduinoJson/Variant/ConverterImpl.hpp:283:51: error: 'std::string' has not been declared" and then as a result there is a massive number of other errors. The problem can be fixed by including <string> before ArduinoJson.h, however I believe that the ArduinoJson library should be able to manage its own dependencies.

I propose a fix in the "Reproduction Code" section.

Troubleshooter's report

  1. The issue happens at compile time
  2. The error is not in the list

Environment

Reproduction code

/***********************************************/
/* This is a suggestion for fixing the problem */
/*                                             */
/* Modify Configuration.hpp as per below       */
/***********************************************/

// Support std::string
#ifndef ARDUINOJSON_ENABLE_STD_STRING
#  ifdef __has_include
#    if __has_include(<string>) && !defined(min) && !defined(max)
#      include <string>
#      define ARDUINOJSON_ENABLE_STD_STRING 1
#    else
#      define ARDUINOJSON_ENABLE_STD_STRING 0
#    endif
#  else
#    ifdef ARDUINO
#      define ARDUINOJSON_ENABLE_STD_STRING 0
#    else
#      define ARDUINOJSON_ENABLE_STD_STRING 1
#    endif
#  endif
#endif

Remarks I suggest to do the same for <string_view> and any other STL type used by ArduinoJson.

bblanchon commented 1 year ago

Hi @margaretselzer,

Thank you very much for reporting this bug šŸ‘ It's fixed in the 6.x branch.

Best regards, Benoit

bblanchon commented 10 months ago

The fix was published with ArduinoJson 6.21.4.