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).
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 a HardFP ABI (very) simple test program. It links with other HardFP binaries without any problems. Now I wanted to use a function from a Softfp ABI library in my code, so I changed the header file (.h) from this library to add the attibute: __ attribute__((pcs("aapcs"))) on every function which uses double args (like: void doSomething(double arg, double arg2)), so I'm telling the toolchain that this library uses softfp ABI. The problem is that the toolchain (arm-linux-androideabi-4.9) is yelling me that:
/media/data_disk/b2g/work/hardfp/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9.x-google/../../../../arm-linux-androideabi/bin/ld: error: /tmp/cc6SmP3D.o uses VFP register arguments, output does not
/media/data_disk/b2g/work/hardfp/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9.x-google/../../../../arm-linux-androideabi/bin/ld: error: /home/jgomez/b2g/build.flatfish.hardfp/out/target/product/flatfish/obj/lib/libc.so uses VFP register arguments, output does not
/media/data_disk/b2g/work/hardfp/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9.x-google/../../../../arm-linux-androideabi/bin/ld: error: /home/jgomez/b2g/build.flatfish.hardfp/out/target/product/flatfish/obj/lib/libstdc++.so uses VFP register arguments, output does not
/media/data_disk/b2g/work/hardfp/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9.x-google/../../../../arm-linux-androideabi/bin/ld: error: /home/jgomez/b2g/build.flatfish.hardfp/out/target/product/flatfish/obj/lib/libm.so uses VFP register arguments, output does not
(Of course, libc, libstdc++, and libm are hardfp too).
It doesn't compile.
So my question is,
How does __attribute__((pcs("aapcs"))) should be used to let HardFP ABI programs link with Softfp ABI binaries?
I thought that this was the purpose of such a flag. Am I wrong?
Thanks!!
Ok, I already figured out the problem.
As I thought, the attribute works as expected. The assembly code generated by the compiler (gcc) if I write the prefix: __attribute__((pcs("aapcs"))) in front of the function declaration, is using r registers to pass the argument values, so the callee, in Softfp mode, works perfect.
I just needed to add this flag to the compiler options:
--no-warn-mismatch
Android/NDK project, worked with NDK versions all the way up to r8c. Under 8d and 8e, I get a compilation error message on the armeabi-v7a build:
Compile++ thumb : myproject <= MyFile.cpp
C:\cygwin\tmp\ccFXOc2F.s: Assembler messages:
C:\cygwin\tmp\ccFXOc2F.s:1935: Error: can't resolve `.data.rel.ro.local' {.data.rel.ro.local section} - `.LPIC44' {*UND* section}
The armeabi, MIPS, and x86 builds for the same project are successful.
It's reliably popping up on the same file. The file is nothing special - vanilla C++, it compiles and works on numerous other platforms (iOS, Windows, NDK r8c to name some). No STL. It does define a healthy amount of string constants though (AKA initialized read/only data). What could be going on?
Already tried a full rebuild, even deleted the obj folder altogether.
The C++ flags are:
LOCAL_CPPFLAGS := -fshort-wchar -fsigned-char -Wno-psabi
I know NDK comes with several versions of GCC; might a toolchain change help? How exactly?
Surely looks like a compiler bug to me. It's related to indexed access to a large chunk of static const data. When I've slightly reformulated a perfectly innocent statement, the error message went away.
Used to be:
//In global scope
static const LPCWSTR Comments[] = {L"A lot of strings here", L"String 2", L"String 3" /* and many more */ }:
void SomeMethod()
{
DoSomething(Comments[i]); //That was the offending line - commenting it out would get rid the error
}
Replaced with:
void SomeMethod()
{
static LPCWSTR pComments = 0;
if(!pComments)
pComments = Comments;
DoSomething(pComments[i]); //Now it works.
}
Ooky, spooky stuff.
I have a map: map < int64_t, Item* > m_items;
When using m_items[one_id], my app crashed.
But if I use map<int64_t, Item*>::iterator iter = m_items.find(one_id), it's ok.
If I need to add an item I must use: m_items.insert(make_pair(one_id, one_item));
Why is this?
Do you know what version of gcc you're using?
If it's gcc 4.5 or earlier this bug in gcc has caused Boost's unordered map's [] operator not to function correctly: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40145
Maybe you're seeing something similar.
If it's gcc 4.6 I'm not sure, but the C++11 at() method will be available to you, it's a little slower, but it is faster than find. http://www.cplusplus.com/reference/map/map/at/