Skip to content

json.hpp:5746:32: error: 'to_string' is not a member of 'std' #136

Closed

Description

@Ingener74

Hello.
On Android i have this messages

  • json.hpp:5746:32: error: 'to_string' is not a member of 'std'
  • json.hpp:6911:36: error: 'strtold' is not a member of 'std'

android ndk have no to_strign realization

Activity

  1. gregmarr commented on Oct 12, 2015

    @gregmarr
    Contributor

    The first one works fine for us, we use the c++-shared library.

    We had to add this function to our codebase to handle the second one.
    inline long double strtold(const char _nptr, char *_endptr)
    {
    return strtod(nptr, endptr);
    }

  2. nlohmann commented on Oct 17, 2015

    @nlohmann
    Owner

    Hey @Ingener74, could you please tell me which compiler you are using?

  3. Ingener74 commented on Oct 17, 2015

    @Ingener74
    Author

    Hello @nlohmann, i am using arm-linux-androideabi-4.9 toolchain for compiling

  4. nlohmann commented on Oct 17, 2015

    @nlohmann
    Owner

    Could this maybe solve your problem: http://stackoverflow.com/a/27589053 ?

  5. Ingener74 commented on Oct 17, 2015

    @Ingener74
    Author

    Thanks @nlohmann, i known this solution :) but that about strtold?
    I wanted to ask whether it will be added to your library? for android

  6. nlohmann commented on Oct 17, 2015

    @nlohmann
    Owner

    Ok, I'll have a look at strtold. It would be easier to check on OSX - is there an OSX version of the compiler you use?

  7. Ingener74 commented on Oct 17, 2015

    @Ingener74
    Author

    On Mac OS X i use compiler

    Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1
    Apple LLVM version 7.0.0 (clang-700.0.72)
    Target: x86_64-apple-darwin14.5.0
    Thread model: posix
    

    but on mac os everythink compiles ok

  8. nlohmann commented on Oct 17, 2015

    @nlohmann
    Owner

    I meant the compiler to create code for Android. Is there a way to cross-compile from OSX?

  9. gregmarr commented on Oct 17, 2015

    @gregmarr
    Contributor

    You need the android NDK.

  10. gregmarr commented on Oct 17, 2015

    @gregmarr
    Contributor

    Yes, it is available for OS X.

  11. Ingener74 commented on Oct 18, 2015

    @Ingener74
    Author

    Hello @nlohmann i agree with @gregmarr, you need Android NDK for compiling
    https://developer.android.com/ndk/downloads/index.html

  12. ZahlGraf commented on Nov 28, 2015

    @ZahlGraf

    Hi,

    for a current project I compiled this library with Android NDK r10e, (it includes gcc 4.9) together with gnustl-shared library.
    The errors mentioned by @Ingener74 are still in the json-lib, thus I created a small patch-file for that.

    On android, it adds the function std::to_string (common workaround implementation, found on stackoverflow) and std::strtold (workaround implementation suggested by @gregmarr).

    Hopefully this patch is usefull for anyone who want to use this library on Android. Maybe linking from the main-README to those compatibility patches would be a good idea.

    Best regards,
    ZG

    From 092170941c6a69cbc3a113b098940b4c03b448c2 Mon Sep 17 00:00:00 2001
    From: Andre Netzeband <andre@netzeband.eu>
    Date: Sat, 28 Nov 2015 13:08:39 +0100
    Subject: [PATCH] Added better android support.
    
    Added Android NDK support.
    ---
     src/json.hpp | 19 +++++++++++++++++++
     1 file changed, 19 insertions(+)
    
    diff --git a/src/json.hpp b/src/json.hpp
    index 1e3cd11..e878295 100644
    --- a/src/json.hpp
    +++ b/src/json.hpp
    @@ -70,6 +70,25 @@ Class @ref nlohmann::basic_json is a good entry point for the documentation.
         using ssize_t = SSIZE_T;
     #endif
    
    +#ifdef __ANDROID__
    +   // Workaround for Android NDK builds (version r10e) that does not support std::to_string and std::strold so far
    +   namespace std
    +   {
    +       template <typename T>
    +       std::string to_string(T Value)
    +       {
    +           std::ostringstream TempStream;
    +           TempStream << Value;
    +           return TempStream.str();
    +       }
    +       
    +       inline long double strtold(const char * str, char ** str_end)
    +       {
    +           return strtod(str, str_end);
    +       }       
    +   }
    +#endif
    +
     /*!
     @brief namespace for Niels Lohmann
     @see https://github.com/nlohmann
    -- 
    2.5.0.windows.1

    BTW: Unit-Tests are running fine on Android Emulator with these changes.

    0001-Added-better-android-support.patch.txt

  13. nlohmann commented on Nov 29, 2015

    @nlohmann
    Owner

    Thanks! I'm on holiday right now and shall have a look then!

  14. nlohmann commented on Dec 6, 2015

    @nlohmann
    Owner

    Thanks @ZahlGraf! I added your patch to the code. @Ingener74, can you please check if this fixes your original issue?

  15. 54 remaining items

  16. JamesBremner commented on Mar 6, 2017

    @JamesBremner

    @nlohmann I think we won't find a solution here:

    OK. The elegance of the parser and the prompt support makes me wish to continue.

    I will fork your repo, install the fix ( the one that works! ) and point my clients there.

  17. tksatware commented on Mar 6, 2017

    @tksatware

    I am using the library with code::blocks 13.12, which uses the gcc installed in the system. gcc is here
    gcc version 4.9.2 (Raspbian 4.9.2-10)
    It works out of the box, but you need to enable C++11 in the compiler options.

    Just go to Settings->Compiler and tick the option
    [ ] Have g++ follow the C++11 ISO C++ language Standard [-std=c++11]

    The library will work perfectly then. "out of the box"!

  18. nlohmann commented on Mar 6, 2017

    @nlohmann
    Owner

    @JamesBremner Can you comment on @tksatware 's observation?

  19. JamesBremner commented on Mar 6, 2017

    @JamesBremner

    I am using the code::blocks v16.1 with C++11 enabled @tksatware must be doing something more, since he using a much older version of codeblocks

  20. tksatware commented on Mar 6, 2017

    @tksatware

    @JamesBremner what does
    gcc -v
    show?

  21. JamesBremner commented on Mar 6, 2017

    @JamesBremner

    C:\Program Files (x86)\CodeBlocks16\MinGW\bin>g++ --version
    g++ (tdm-1) 4.9.2

  22. JamesBremner commented on Mar 6, 2017

    @JamesBremner

    gcc version 4.9.2 (Raspbian 4.9.2-10)

    This looks very linuxy. I am runninning mingw under windows.

  23. tksatware commented on Mar 6, 2017

    @tksatware

    @JamesBremner I will install it Code::Blocks tomorrow under Windows and have a look. On Windows, I am using VS2015 Update 3, which also works fine. The mingw road was always too hacky for me.
    But actually, this is gcc 4.9.2 in disguise and should work.

  24. JamesBremner commented on Mar 6, 2017

    @JamesBremner

    Here is the v2.1.1 release fixed up to compile under windows code::blocks v16.1

    https://github.com/JamesBremner/nlohmann-json-parser-for-mingw

  25. nlohmann commented on Mar 6, 2017

    @nlohmann
    Owner

    Nice work. Please note that the library is called "JSON for Modern C++" and is more than just a parser, so I would suggest you change the README from "This is a copy of the modern C++ JSON parser" to "This is a copy of JSON for Modern C++".

  26. JamesBremner commented on Mar 6, 2017

    @JamesBremner

    @nlohmann Done!

  27. gregmarr commented on Mar 6, 2017

    @gregmarr
    Contributor
    If more that one file includes json.hpp, then I get multiple definition linker errors.
    The problem is that the implementation of the replacement functions cannot be placed in the header, but must be in a single cpp file.
    

    Sounds like you were missing an inline.

  28. JamesBremner commented on Mar 6, 2017

    @JamesBremner

    @gregmarr Good idea. I have re-implemented the missing functions in the header file using inline and so the cpp source file is no longer needed. At the cost of a little bloat, the neat header only design is restored.

    I have to note that the inline was also missing form the fix that you posted back in May.

  29. JamesBremner commented on Mar 6, 2017

    @JamesBremner

    I have replaced my old JSON parser with yours in my first project - a simple open source scheduler. The application source code replacement was very straightforward ( once the compile problems were sorted ).

    I do like the automatic handling of json objects versus json arrays. So far, everything is simply just a nlohmann::json

    FYI, here is the commit

    JamesBremner/schedule@46a5002

  30. gregmarr commented on Mar 6, 2017

    @gregmarr
    Contributor

    @JamesBremner Cool. FYI, I wrote a template function, which is automatically inline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions