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?
Related
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.
Am trying to build an android ndk app using clang instead of gcc, for know i have tried this
in the Android.mk
NDK_TOOLCHAIN_VERSION := clang
LOCAL_CLANG :=true
LOCAL_LDLIBS := -lc++_static
LOCAL_CFLAGS := -std=c++11
and in the Application.mk
APP_PLATFORM := android-9
APP_STL := libc++_static
APP_CPPFLAGS := -fexceptions -frtti
APP_ABI := armeabi-v7a
but it always give me link errors with the std library.
Any help is appreciated !
There are several mistakes in your *.mk files:
libc++_static isn't a proper value for APP_STL, it should be c++_static here.
NDK_TOOLCHAIN_VERSION has no effect when set inside Android.mk, it should be set inside Application.mk
LOCAL_CLANG is a variable used inside system modules from AOSP, not when using the NDK.
Since you're setting APP_STL as c++_static, the NDK toolchain will correctly tell the linker what lib to use, you shouldn't add LOCAL_LDLIBS := -lc++_static.
Also, you set APP_ABI to only armeabi-v7a, is it on purpose ? Android runs on other architectures as well and you'll get better performance on these if you also compile your libraries accordingly. You can either set APP_ABI to all or to a list of architectures armeabi-v7a x86...
In summary:
Android.mk
LOCAL_CFLAGS := -std=c++11
Application.mk
NDK_TOOLCHAIN_VERSION := clang
APP_PLATFORM := android-9
APP_STL := c++_static
APP_CPPFLAGS := -fexceptions -frtti
APP_ABI := all
If you continue having some troubles compiling your code, please show the exact errors you're getting.
The building settings are correct,
mostly this is happens because you are linking with library that use gcc instead of clang. check if all your linked library using clang !
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 am creating a new SDK component (application) based on the sample device located at /device/sample
the idea is to port an existing application written using C++, which utilizes lots of templates, RTTI, exceptions, STL; from the documentation it is clear that if I build my application with gnustl_static/gnustl_shared support this will provide me with all the support I need.
Now if I am creating a NDK application, which has Application.mk I know adding APP_STL := gnustl_static in it is one way to do it.
But as the component is part of new device sdk-addon.
Q1. I dont know how to provide Application.mk for native C++ application/component being build part of sdk-addon.
Q2. As per my knowledge I only have access to Android.mk and I am looking for a way to add support for gnustl_static using only Android.mk
I have tried various combinations of following options in Android.mk without any luck
LOCAL_CPPFLAGS += -fexceptions
LOCAL_CPPFLAGS += -frtti
LOCAL_SRC_FILES += libs/$(TARGET_ARCH_ABI)/libstdc++.a
LOCAL_STATIC_LIBRARIES := gnustl_static
Do let me know if you have any suggestions, thanks.
For now I have decided to avoid using RTTI/exceptions and I have decided to go with stlport
LOCAL_SHARED_LIBRARIES += libstlport
I guess same should also work with gnustl.