Using C++'s std::trunc in android errors out saying trunc is not a member of std
Is there an alternative or a work around ?
<cmath> is included in my code.
My environment is:
NDK Version is r13b
ANDROID_NDK_PLATFORM = 23
ANDROID_NDK_TOOLCHAIN_VERSION = 4.9
Related
I'm trying to add the 22.0.7026061 NDK to Qt creator, but this version does not contain the platforms folder. Qt creator uses the following code to check the validity of the NDK and as a result I cannot add the 22nd version. In addition, I did not find any clear explanation why this paltrforms does not exist.
bool AndroidConfig::isValidNdk(const QString &ndkLocation) const
{
auto ndkPath = Utils::FilePath::fromUserInput(ndkLocation);
const Utils::FilePath ndkPlatformsDir = ndkPath.pathAppended("platforms");
return ndkPath.exists() && ndkPath.pathAppended("toolchains").exists()
&& ndkPlatformsDir.exists() && !ndkPlatformsDir.toString().contains(' ')
&& !ndkVersion(ndkPath).isNull();
}
What can I do? I need exactly the 22nd version, the versions below are normally added.
From Changelog-r21:
The legacy toolchain install paths will be removed over the coming
releases. These paths have been obsolete since NDK r19 and take up a
considerable amount of space in the NDK. The paths being removed are:
platforms
sources/cxx-stl
sysroot
toolchains (with the exception of toolchains/llvm)
As for what you can do? I don't think much, you'll have to patch this part of Qt to use newer directories (e.g toolchains/llvm for platforms). You can also report this as a bug to Qt devs.
android.ndk {
moduleName = "hello-jni"
stl = "stlport_static"
CFlags.add("-std=iso9899:2011") // I have also used "-std=c11"
ldLibs.addAll(["android", "log"])
}
I still cannot see memset_s in jni C code. It says undefined reference.
In my c code i have also included string.h, stdlib.h, and stdio.h and also
#define STDC_WANT_LIB_EXT1 1
Still cannot get rid of the error undefined reference error.
If i add the flag Allow_Undefined_symbols it compiles but when ever i call the function memset_s it crashes.
The questions i would like to ask are as follows :
1) In which of the Android NDK tool chains can we get the C11 memset_s api?
2) The other question i have is how can we change the default tool chain for android in the latest android studio with experimental gradle alpha5?
This functionally of "Annex K" in the C11 standard is optional. It is not implemented in many C libraries.
You can test for conformance to Annex K by means of the macro __STDC_LIB_EXT1__.
I was not able to find any tool chain that supports C11 for NDK. So i have used a compliant solution for c99 from the following link:
https://www.securecoding.cert.org/confluence/display/c/MSC06-C.+Beware+of+compiler+optimizations
Which you can customize for your own purpose. I am adding this solution for any one in need.
I have created a shared object for Android in Visual Studio 2015.
It works fine so far, but pop_back() for a wstring does not work:
wstring element = "JustATest!";
if (element.back() == L'!')
{
element.pop_back();
}
VS2015 tells me:
"no member named 'pop_back' in 'std::basic_string<wchar_t>'".
Can anybody tell me how to get rid of this error?
I have no idea why this should not work.
Is that because for some reason VS2015 does not use C++11 here?
Thank you for the help!
Edit: Another error:
When I try to use _wtoi, VS tells me: "use of undeclared identifier '_wtoi'.
Very very strange.
You need to turn on STL support. Turn on STL with Configuration Properties -> General -> Use of STL. Good options are LLVM libc++ static library (fewer features, more compatible with CLANG) and GNU STL static library (more features, I had an issue that required me to turn the CLANG optimizer to -Oz to prevent a segfault).
I want to try new features of c++ (especially C++11) on my Android native project.
How to determine which C++ Standard supported by NDK Revision 9c?
Update
For instance in case
int arr[] = {1,2,3,4,5};
for(int& e : arr)
{
e = e*e;
}
I got
error: range-based-for loops are not allowed in C++98 mode
Is this means that NDK support only C++98 Standard?
According to the Android NDK docs, version 9c supports gcc 4.8 and Clang 3.3, both of which are fully C++11 compliant. To actually make use of C++11, you need to compile with the flag -std=c++11.
I tried to use the following function to check whether std::async is supported in android ndk with Eclipse along with cygwin in windows. The function I used is the following
Machine: 64bit win 8 with cygwin
Android: r8e
Eclipse: Juno 4.2.1
ADT: 22.0.1
struct Foo
{
Foo() : data(0) {}
void sum(int i) { data +=i;}
int data;
};
int main()
{
Foo foo;
auto f = std::async(&Foo::sum, &foo, 42);
f.get();
std::cout << foo.data << "\n";
}
I get the following error:
Description Resource Path Location Type
invalid use of incomplete type 'std::__async_sfinae_helper::type {aka struct std::future}' Sample.cpp /Cli13/jni line 63 C/C++ Problem
Note: I have set the _GLIBCXX_HAS_GTHREADS and also the GXX_EXPERIMENTAL_CXX0X along with the ATOMIC_INT_LOCK_FREE... By default the ndk uses 4.6 toolchain. I had to include the gnu-libstd++ for 4.7 manually in Properties-> C/C++ -> Includes. Is there any work around to make the std::async working???
Thank You.
Android NDK r8e does not have the full run-time library support of C++11. You will need to compile your own NDK using some third-party stdlib or wait Google to include the Clang 3.3 in the NDK which is C++11 feature-complete.