NDKr8b and gnu++0x status - android

I try to use gnu++0x features in my native android code. I'm using the lastest version (r8b, with toolchain 4.6) and while code using std::chrono or std::thread works well using linux gcc 4.6, it seems that these features are not supported in android ndk.
To compile, I use the following flags in the Application.mk file :
APP_CPPFLAGS := -std=gnu++0x
APP_STL := gnustl_shared
APP_GNUSTL_CPP_FEATURES := rtti exceptions
May I do something wrong ? Is there a link to know the status of the c++0x support in android ndk ?
Thanks a lot !
Regards,
JB
Just a sample code like this :
std::chrono::time_point<std::chrono::system_clock> start =
std::chrono::system_clock::now();
std::chrono::milliseconds duration (100);
std::this_thread::sleep_for(duration);
std::chrono::milliseconds elapsedTime =
std::chrono::duration_cast<std::chrono::milliseconds>
(std::chrono::system_clock::now() - start);
With headers,
#include <chrono>
#include <thread>
Using ndk-build, I've got an error message like this :
error: 'chrono' in namespace 'std' does not name a type
....
error: 'std::this_thread' has not been declared
And all about chrono and thread !

I know this is an old question, but I succeed in using chrono in the Android NDK. I just added this line to my Android.mk:
LOCAL_CPPFLAGS := -std=c++11
I also added this line in Application.mk to solve some issues I had using chrono:
NDK_TOOLCHAIN_VERSION := 4.8
Now you have support for c++11 including chrono.

<NDK_root_folder>/docs/CPLUSPLUS-SUPPORT.html
that's all, here you get all the informations and the support that your NDK can give to your C++ code.

have a try:
NDK_TOOLCHAIN_VERSION := 4.8
NDK_TOOLCHAIN_VERSION
Define this variable to either 4.4.3 or 4.6 to select version of GCC compiler.
4.6 is the default

Related

Android can't include linux in C program with Android.mk

I'm trying to compile a C program for Android 6. This is my Android.mk:
APP_PLATFORM := android-23
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Enable PIE manually. Will get reset on $(CLEAR_VARS). This
# is what enabling PIE translates to behind the scenes.
LOCAL_CFLAGS += -fPIE -DHAVE_FANOTIFY=1 -DHAVE_SYS_FANOTIFY=0
LOCAL_LDFLAGS += -fPIE -pie
# give module name
LOCAL_MODULE := fsmon
# list your C files to compile
LOCAL_SRC_FILES := inotify.c fanotify.c util.c main.c
# this option will build executables instead of building library for android application.
include $(BUILD_EXECUTABLE)
In the fanotify.c following include is written:
#include <linux/fanotify.h>
When I try to use ndk-build, following error appears:
fsmon/jni/fanotify.c:51:10: fatal error: 'linux/fanotify.h' file not found
#include <linux/fanotify.h>
^
The header fanotify.h is present in the ndk path /Android/Sdk/ndk-bundle/sysroot/usr/include/linux
Any suggestions?
EDIT: Same error if I try to include sys/fanotify.h
You can specify additional include paths for your module using LOCAL_C_INCLUDES.
LOCAL_C_INCLUDES := /Android/Sdk/ndk-bundle/sysroot/usr/include/
https://developer.android.com/ndk/guides/android_mk.html#mdv
The NDK historically didn't backport headers to old releases, but we've reworked things in r14 so this is possible: https://android.googlesource.com/platform/ndk/+/ndk-r14-release/docs/UnifiedHeaders.md
By default in r14 you still get the old form of the headers. The new "unified headers" have the headers you're looking for. If you want to try unified headers, set APP_UNIFIED_HEADERS := true in your Application.mk (settings for other build systems can be found in the link above).
In r15 (first beta due out soon), the default has changed to the new headers, and the option for disabling them has changed (see the same doc in r15 for changes in options: https://android.googlesource.com/platform/ndk/+/ndk-r15-release/docs/UnifiedHeaders.md).

Crystax NDK linker error

I'm trying to get working Crystax NDK example and have the following error (I've made up PATH/TO/MY/CRYSTAXNDK/ of course):
$ ndk-build APP_ABI=armeabi-v7a
[armeabi-v7a] Executable : test-boost
PATH/TO/MY/CRYSTAXNDK/crystax-ndk-10.3.1/sources/boost/1.59.0/include/boost/archive/detail/oserializer.hpp:88: error: undefined reference to 'boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
Actually, this example is a bit outdated and I've already solved this error:
Android NDK: ERROR:PATH/TO/MY/CRYSTAXNDK/crystax-ndk-10.3.1/sources/boost/1.59.0/Android.mk:boost_atomic_static: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that PATH/TO/MY/CRYSTAXNDK/crystax-ndk-10.3.1/sources/boost/1.59.0/libs/armeabi-v7a/gnu-/libboost_atomic.a exists or that its path is correct
by adding NDK_TOOLCHAIN_VERSION=4.9 into Android.mk.
I've also replaced $(call import-module,boost/1.57.0) with $(call import-module,boost/1.59.0) to call actual version of Boost library.
So, my Android.mk looks as following:
# Android.mk
LOCAL_PATH := $(call my-dir)
NDK_TOOLCHAIN_VERSION = 4.9
include $(CLEAR_VARS)
LOCAL_MODULE := test-boost
LOCAL_SRC_FILES := test.cpp gps.cpp
LOCAL_STATIC_LIBRARIES := boost_serialization_static
include $(BUILD_EXECUTABLE)
$(call import-module,boost/1.59.0)
My crystax-ndk directory is in a system path. I understand that the cause of my problem is that NDK linker is unable to find proper Boost libraries. But I don't know how to configure it in such a way that it will automatically choose libraries depending on the target architecture.
Please help me to figure out the configuration of the linker!
Thanks.
This is bug. Shortly speaking, libboost_serialization.so was built with GNU libstdc++ v5, but when you call ndk-build, it link final binary with GNU libstdc++ v4.9, which is binary incompatible with GNU libstdc++ v5 (specifically, std::basic_string; if interested, please look here for details).
This is fixed by a7c363377 and will be included to the next bug-fix release (10.3.2). In the meantime, you can apply that patch manually on your crystax-ndk-10.3.1 file tree to solve the problem.
I ran into the same problem following the CrytaX blog tutorial. I fixed it by adding the following
# Application.mk
APP_ABI := all
NDK_TOOLCHAIN_VERSION := 5
APP_PLATFORM := android-19
The 2nd line fixed the ndk-build Boost gcc lib path error. The 3rd line fixed the "only position independent executables" problem when invoking the executable.

chrono partially not supported in Android NDK

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.

Android bitmap.h is not found for native code compile

I am trying to compile code using the Android NDK. I have previously used this code fine, but changed one thing in it and now it will not compile. The error that shows up is:
"Compile++ thumb : filters <= filters.cpp
C:/Android/my-app//jni/filters.cpp:4:28: fatal error: android
/bitmap.h: No such file or directory
compilation terminated.
make: *** [C:/Android/my-app//obj/local/armeabi/objs/filters/
filters.o] Error 1
My bitmap.h file is defined in the library as:
#include <android/bitmap.h>
I know that bitmap.h is only there after a target-skd build of 8 or higher, and mine is a target of 10 and min of 8. Any suggestions? This is driving me crazy and used to work!Thanks for any help you can provide.
Edit: Here is my Android.mk file also
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := filters
LOCAL_SRC_FILES := filters.cpp
LOCAL_LDLIBS := -lm -llog -ljnigraphics
include $(BUILD_SHARED_LIBRARY)
Got it to work. I was using SDK tools revision 20, and platform-tools revision 12. In order to get it to compile, I had to specify the APP_PLATFORM in the command line (apparently these revisions default to something else).
Just ran:
ndk-build APP_PLATFORM=android-8
and it built!
Insert APP_PLATFORM=android-8 into file Application.mk
Well, the answer bellow helped me also.
I tried setting the APP_PLATFORM variabile to android-10 from Application.mk (as I expected this option should also be where the APP_ABI is), but that didn't help.
Pretty non-intuitive, but whatever works, right..?

Android NDK won't build library because Bitmap.h is missing?

I'm using the Android NDK to build a library. I had everything working well, but then I needed to change a package name which is referenced in the library. I tried to build the library again once I made the change, by calling ndk-build in its folder, but this is the only output I get and it does not seem to be fully building:
C:\my-app\jni>ndk-build -B
"Compile++ thumb : filters <= filters.cpp
C:/a-fa-outsidelands//jni/filters.cpp:4:28: fatal error: android/bitmap.h: No such file or directory
compilation terminated.
This then leads to an unsatisfied link error when I try to run the application. I'll post my .mk file, but I don't think that should matter because my previous library was working with this .mk file. I'm doing the rebuild (the -B parameter) because it is over a previous build. Any suggestions? Here's my .mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := filters
LOCAL_SRC_FILES := filters.cpp
LOCAL_LDLIBS := -lm -llog -ljnigraphics
include $(BUILD_SHARED_LIBRARY)
Thanks for the help.
What's the android:targetSdkVersion in the app's manifest? IIRC, bitmap.h was not introduced until SDK v8.
EDIT: Was the last successful build on the same machine, with the same NDK version? Does the #include line use <android/bitmap.h> as opposed to "android/bitmap.h"?
EDIT2: Did the targetSdkVersion change since the last build? I found a funny thing: there's no android-10 under android-ndk-xx\platforms. Try creating a blank android-10 folder under android-ndk-xx\platforms and copying the contents of android-9 there. I'm honestly not sure what else to check.
I got the same problem. Then I found this answer.
Android bitmap.h is not found for native code compile
Just ran:
ndk-build APP_PLATFORM=android-8

Categories

Resources