I'm having problems with the android ndk r10. I get the following: std::string has not been declared. I watched other forum threads like this, but nope of them helped me. My Application.mk looks like this:
APP_PLATFORM := android-14
APP_ABI := armeabi-v7a # build for the ARM version of MCPE
APP_CFLAGS := -O2 -std=gnu99 # optimization level 2, use C99 (for decleations in for loops, etc)
APP_CPPFLAGS := -std=c++11
LOCAL_CFLAGS := -std=c++11
APP_STL := stlport_static
Please help me!
The class std::string has not been declared because it's not there. Unfortunately, there is no std::string in NDK. Some ports of std::string exist, I remember I found one or two, but finally I decided just not to use std::string. Why? Because we already have Java strings and C strings, Java strings come from JNI calls, C strings come from files, and if you introduce one more string type, it will be more conversion than usage.
EDIT: but read the comment below.
Related
I am building an android native library i.e .so file using ndk-build and using it in my cocos2dx project. When I access any of the method of the library that returns empty string, it crashes straight away on OS higher than 5.0 only. Below is my Application.mk file, I have tried of add different options but no avail.
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -std=c++11 -fsigned-char -fexceptions
APP_LDFLAGS := -latomic
APP_ABI := armeabi
APP_PLATFORM := android-9
If I return anything else than empty string like "0", it works fine. But on just accessing the method that return empty string, is a straight crash. Any help will be highly appreciated.
I know there is a possible dup here:
error: 'stod' was not declared in this scope but I already tried what advised there.
I try to compile a C++ application in Android NDK.
I get error:
'stod' was not declared in this scope
I enabled C++ 11 in Application.mk:
APP_ABI := x86
APP_STL := gnustl_static
NDK_TOOLCHAIN_VERSION:= 4.8
APP_CPPFLAGS += -fexceptions -std=c++11 -fpermissive -frtti -pthread
What else should I do in order to get rid of this error?
I guess you probably figured out that this isn't part of the current Android NDK (10). There are several missing pieces from the C++11 libraries, such as regex functionality and to_string, etc.
I'm trying to use chrono with the Android NDK. I had some success so far but some features are not supported.
I added this line in my Android.mk:
LOCAL_CPPFLAGS := -std=c++11
My Application.mk file:
APP_ABI := armeabi-v7a
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_PLATFORM := android-9
The first problem is that steady_clock is not defined. This line:
std::chrono::steady_clock::time_point time = std::chrono::steady_clock::now();
generates this compile error:
error: 'std::chrono::steady_clock' has not been declared
I found out I can use monotonic_clock instead and it works, but this type is supposed to have been replaced by steady_clock.
The second problem is that the property is_steady is not defined for any type:
LOGD("high_resolution_clock is steady: ", std::chrono::monotonic_clock::is_steady);
generates this compile error:
error: 'is_steady' is not a member of 'std::chrono::monotonic_clock'
Does someone know if there is full support for chrono in the NDK? I also would like to know if it's a good idea to use c++11 with the NDK. I'm not sure if it's stable or it's likely to change in the future.
Well I just found a solution. Looks like you need to tell the gcc version you are going to use (I guess it's the 4.7 by default). I just added this line in my Application.mk
NDK_TOOLCHAIN_VERSION := 4.8
Now I can use steady_clock and is_steady.
I'm trying to compile a C++ code with ndk-build and I get the next error:
'sqrtl' was not declared in this scope
I include cmath in the source code and configure the application.mk as follow:
APP_CPPFLAGS := -frtti -fexceptions
APP_STL := gnustl_static
APP_ABI := armeabi-v7a
APP_PLATFORM := android-10
Searching into ndk sources, I found that sqrtl is defined in cmath, together with other xxxl functions (cosl, sinl, etc).
I don't know if missing a define or something like that.
Can someone help me ?
So you could find the functions in math.h, but according to
https://groups.google.com/forum/?fromgroups=#!topic/android-ndk/0jVfs3wCeGs
android doesn't support long double so not sure you're going to get any success using the standard headers... Could you use the plain double version?
I can't seem to get the following trivial code to compile/link and the problem seems specific to std::wstring and the gnustl_static C++ library. Any help would be appreciated.
main.cpp file:
#include <string>
int main(void)
{
std::wstring wtest(L"Test");
return 0;
}
Application.mk file:
APP_CFLAGS += -fexceptions
APP_STL := gnustl_static
Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := TestWCharApp
LOCAL_CFLAGS := -D_GLIBCXX_USE_WCHAR_T
LOCAL_SRC_FILES := main.cpp
include $(BUILD_EXECUTABLE)
When attempting to link the above application using gnustl_static I get the following error message:
undefined reference to `std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::basic_string(wchar_t const*, std::allocator<wchar_t> const&)'
If I change APP_STL to stlport_static and define _STLP_HAS_WCHAR_T everything seems to compile/link/run fine. I verify it works by uploading the exe to the emulator and running it via the shell.
I'm going to need to use the gnustl implementation for c++ exception support otherwise I'd go with stlport_shared. Any clues as to why the above sample works for stlport_static but not gnustl_static?
It's a problem with the file $NDK/sources/cxx-stl/gnu-libstdc++/Android.mk
Add the following line to that file:
LOCAL_MODULE_FILENAME := libstdc++
What's your target OS? According to this thread, gnustl_static doesn't support wchar_t prior to 2.3.
From the platforms\android-*\arch-arm\usr\include\wchar.h header file:
/* IMPORTANT: Any code that relies on wide character support is essentially
* non-portable and/or broken. the only reason this header exist
* is because I'm really a nice guy. However, I'm not nice enough
* to provide you with a real implementation. instead wchar_t == char
* and all wc functions are stubs to their "normal" equivalent...
*/
Funny though that running the following simple program in an android emulator show that wchar_t is 4 bytes.
#include <stdio.h>
int main(void)
{
printf("Size of wchar is %d\n", sizeof(wchar_t));
return 0;
}
Another thing to consider. The JNI bridge provides two useful ways to marshal string data. GetStringUTFChars (returns const char ) and GetStringChars (returns jchar). How many bytes do you think a jchar is defined as ... 2.
Make sure you run "ndk-build clean" and manually delete your libs/ and obj/
directories.
(Reference)