I have a perfectly working NDK project that uses the latest NDK r10d and GCC 4.9 toolchain. I've decided to try building it with clang instead. I've set NDK_TOOLCHAIN_VERSION := clang in Application.mk, and also replaced APP_STL := gnustl_static with APP_STL := c++_static. I didn't make any other adjustments, because upon Googling the matter for a while, I decided I don't need any. I have successfully compiled all the sources, but linking throws a set of 3 errors for every single object file (error message in bold):
c:/Development/Android_SDK/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin\ld.exe:
error: ./obj/local/armeabi-v7a/objs/native_lib/main.o:1:3:
invalid character
c:/Development/Android_SDK/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin\ld.exe:
error: ./obj/local/armeabi-v7a/objs/native_lib/main.o:1:3:
syntax error, unexpected $end
c:/Development/Android_SDK/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin\ld.exe:
error: ./obj/local/armeabi-v7a/objs/native_lib/main.o: not
an object or archive
This happens in release (APP_OPTIM := release APP_CFLAGS := -O3), but not in debug (APP_OPTIM := debug APP_CFLAGS := -O0 -g -gdwarf-2). With debug build, everything's fine!
Here's my entire Application.mk:
APP_OPTIM := release
APP_CFLAGS := -O3 -flto -fwhole-program
APP_STL := c++_static
APP_CPPFLAGS += -fexceptions -frtti -std=c++11 -rdynamic -funwind-tables
APP_CFLAGS += -Wno-deprecated-declarations -rdynamic -funwind-tables -Wno-deprecated-register
GLOBAL_ARM_MODE := arm
APP_ABI := armeabi-v7a
APP_PLATFORM := android-15
NDK_TOOLCHAIN_VERSION := clang
APP_GNUSTL_FORCE_CPP_FEATURES := exceptions rtti
#Position-independent executable
APP_PIE := true
APP_MODULES := native_lib
What could be the problem here?
Note that it uses ld from GCC 4.8, is that correct?
P. S. This is on Windows x64.
Related
I am trying to compile a NDK only app (command line app).
I was using C++11 for many things, and I recently added threads:
#include <thread>
Now my compilation is not working, even though it works for map/deque/vector/....
With the following error:
jni/common.h:24:10: fatal error: 'thread' file not found
#include <thread>
^
1 error generated.
This is my Application.mk:
APP_PLATFORM := android-18
APP_CPPFLAGS := -Wall -frtti -fexceptions -fpermissive
APP_ABI := armeabi-v7a
APP_STL:=stlport_static
NDK_TOOLCHAIN_VERSION := clang
APP_OPTIM := release
This is my Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := XXXX
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/XXXXX
LOCAL_SRC_FILES := ....
LOCAL_C_FLAGS := -O3 -std=c++11
LOCAL_CXX_FLAGS := -O3 -std=c++11
LOCAL_LDLIBS := -llog
include $(BUILD_EXECUTABLE)
I am using NDK 10d.
Ok, I'll answer myself :)
Seems that APP_STL:=stlport_static does not support C++ threads. Changing to the APP_STL:=gnustl_static solves the problem.
I'm using Android NDK r10d. My application.mk is setup like so:
APP_CFLAGS := -DANDROID -DBUILD_OGLES2
APP_CPPFLAGS := $(APP_CFLAGS) -fexceptions -frtti -std=c++14
APP_STL := gnustl_static
APP_ABI := armeabi-v7a
APP_PLATFORM := android-15
NDK_TOOLCHAIN_VERSION := clang
I am using std::make_unique in my code and it isn't compiling (says it isn't found). This feature should be available in STL starting with C++14. I did some poking around and it seems that clang isn't using GNU STL 4.9 in the NDK. If it were, it would be available since I see it inside <memory> header.
What am I missing here? Is there a way to use 4.9 GNU STL with clang?
make_unique isn't available through gnustl from clang. You can try using LLVM libc++ instead. Set this inside your Application.mk:
APP_STL := c++_static
NDK_TOOLCHAIN_VERSION := clang
edit:
Forcing the use of GNU STL 4.9 (by changing TOOLCHAIN_VERSION inside android-ndk-r10d/toolchains/*toolchain_name*-clang3.5/setup.mk) makes the build crash:
clang++: /s/ndk-toolchain/src/llvm-3.5/llvm/tools/clang/lib/AST/DeclBase.cpp:1293: clang::DeclContext::lookup_result clang::DeclContext::lookup(clang::DeclarationName): Assertion 'DeclKind != Decl::LinkageSpec && "Should not perform lookups into linkage specs!"' failed.
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 can't seem to get the android NDK to have C++11 support. Considering I'm only porting another person's project to android through the ndk, I really don't have any experience with c++ before now.
My application.mk:
NDK_TOOLCHAIN_VERSION := clang
APP_STL := c++_static
APP_CPPFLAGS := -std=c++11 -frtti -fexceptions
APP_ABI := all
APP_PLATFORM := android-8
Thanks in advance!
I have recently purchased a book to assist in my development of C++ for Android which contained some code samples. However, when I come to build some of the sample code, I receive the following error:
C:\ndk\android-ndk-r9\ndk-build.cmd all
"Compile++ : Chapter10 <= Chapter10.cpp
process_begin: CreateProcess(NULL, C:/ndk/android-ndk-r9/toolchains/arm-linux-androideabi-4.7/prebuilt/windows/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi/objs/Chapter10/Chapter10.o.d -fno-exceptions -fno-rtti -Ijni -IC:/ndk/android-ndk-r9/sources/android/native_app_glue -IC:/ndk/android-ndk-r9/sources/cxx-stl/stlport/stlport -IC:/ndk/android-ndk-r9/sources/cxx-stl//gabi++/include -Ijni -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security -frtti -c jni/Chapter10.cpp -o ./obj/local/armeabi/objs/Chapter10/Chapter10.o, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [obj/local/armeabi/objs/Chapter10/Chapter10.o] Error 2
The make file is as shown below:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_MODULE := Chapter10
LOCAL_SRC_FILES := Chapter10.cpp \
(Other cpp Files . . . )
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2 -lOpenSLES
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
The Application.mk file is as below:
APP_PLATFORM := android-9
APP_STL := stlport_static
NDK_TOOLCHAIN_VERSION := 4.7
This was compiled using ADT v22.2.1 and Android NDK r9 on a Windows 7 Machine.
The NDK was installed to 'C:\ndk\android-ndk-r9\'.
Android NDK r9 contains the following toolchains:
arm-linux-androideabi-4.6
arm-linux-androideabi-4.8
arm-linux-androideabi-clang3.2
arm-linux-androideabi-clang3.3
llvm-3.2
llvm-3.3
mipsel-linux-android-4.6
mipsel-linux-android-4.8
mipsel-linux-android-clang3.2
mipsel-linux-android-clang3.3
x86-4.6
x86-4.8
x86-clang3.2
x86-clang3.3
There is no toolchain for gcc 4.7. However, your Application.mk contains the line:
NDK_TOOLCHAIN_VERSION := 4.7
Which tells the NDK to look for the 4.7 toolchain. And it fails.
So, the solution to your problem is changing the NDK_TOOLCHAIN_VERSION variable to 4.6, 4.8, clang3.2, clang3.3, or just clang (which will use the most recent version of Clang available in the NDK).
Check your project path if is contain spaces and non-english characters.
I moved my project into somewhere without spaces, re-build it and works.