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:5746:32: error: 'to_string' is not a member of 'std' #136
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);
}
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.
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"!
@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.
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++".
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.
@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.
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
Activity
gregmarr commentedon Oct 12, 2015
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);
}
nlohmann commentedon Oct 17, 2015
Hey @Ingener74, could you please tell me which compiler you are using?
Ingener74 commentedon Oct 17, 2015
Hello @nlohmann, i am using arm-linux-androideabi-4.9 toolchain for compiling
nlohmann commentedon Oct 17, 2015
Could this maybe solve your problem: http://stackoverflow.com/a/27589053 ?
Ingener74 commentedon Oct 17, 2015
Thanks @nlohmann, i known this solution :) but that about strtold?
I wanted to ask whether it will be added to your library? for android
nlohmann commentedon Oct 17, 2015
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?Ingener74 commentedon Oct 17, 2015
On Mac OS X i use compiler
but on mac os everythink compiles ok
nlohmann commentedon Oct 17, 2015
I meant the compiler to create code for Android. Is there a way to cross-compile from OSX?
gregmarr commentedon Oct 17, 2015
You need the android NDK.
gregmarr commentedon Oct 17, 2015
Yes, it is available for OS X.
Ingener74 commentedon Oct 18, 2015
Hello @nlohmann i agree with @gregmarr, you need Android NDK for compiling
https://developer.android.com/ndk/downloads/index.html
ZahlGraf commentedon Nov 28, 2015
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
BTW: Unit-Tests are running fine on Android Emulator with these changes.
0001-Added-better-android-support.patch.txt
nlohmann commentedon Nov 29, 2015
Thanks! I'm on holiday right now and shall have a look then!
nlohmann commentedon Dec 6, 2015
Thanks @ZahlGraf! I added your patch to the code. @Ingener74, can you please check if this fixes your original issue?
54 remaining items
JamesBremner commentedon Mar 6, 2017
@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.
tksatware commentedon Mar 6, 2017
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"!
nlohmann commentedon Mar 6, 2017
@JamesBremner Can you comment on @tksatware 's observation?
JamesBremner commentedon Mar 6, 2017
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
tksatware commentedon Mar 6, 2017
@JamesBremner what does
gcc -vshow?
JamesBremner commentedon Mar 6, 2017
C:\Program Files (x86)\CodeBlocks16\MinGW\bin>g++ --version
g++ (tdm-1) 4.9.2
JamesBremner commentedon Mar 6, 2017
gcc version 4.9.2 (Raspbian 4.9.2-10)
This looks very linuxy. I am runninning mingw under windows.
tksatware commentedon Mar 6, 2017
@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.
JamesBremner commentedon Mar 6, 2017
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
nlohmann commentedon Mar 6, 2017
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++".
JamesBremner commentedon Mar 6, 2017
@nlohmann Done!
gregmarr commentedon Mar 6, 2017
Sounds like you were missing an
inline.JamesBremner commentedon Mar 6, 2017
@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.
JamesBremner commentedon Mar 6, 2017
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::jsonFYI, here is the commit
JamesBremner/schedule@46a5002
gregmarr commentedon Mar 6, 2017
@JamesBremner Cool. FYI, I wrote a template function, which is automatically
inline.