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 !
Code written in C/C++ can be compiled to ARM, or x86 native code (or their 64-bit variants) using the Android Native Development Kit (NDK). The NDK uses the Clang compiler to compile C/C++. GCC was included until NDK r17, but removed in r18 in 2018.
libc++ LLVM's libc++ is the C++ standard library that has been used by the Android OS since Lollipop, and as of NDK r18 is the only STL available in the NDK. Note: For full details of the expected level of C++ library support for any given version, see the C++14 Status, C++17 Status, and C++20 Status pages.
To compile and debug native code for your app, you need the following components: The Android Native Development Kit (NDK): a set of tools that allows you to use C and C++ code with Android. CMake: an external build tool that works alongside Gradle to build your native library.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With