开发者

Which compiler does Android NDK use?

开发者 https://www.devze.com 2023-03-18 00:55 出处:网络
I\'m writing ARM NEON-based code for an Android application and I was struggling with certain compiler flags not being recognized. I later realized that support for those flags was only added quite re

I'm writing ARM NEON-based code for an Android application and I was struggling with certain compiler flags not being recognized. I later realized that support for those flags was only added quite recently and that my GCC version is older. I'm doing the whole thing on Windows and am limited by what versions Cygwin has to offer. Here's my question: before I go and try to build GCC 4.6.0 on my Windows machine and make Cygwin like it, will it work for me or does the NDK use its own version of t开发者_C百科he GCC and my upgrade will not at all affect it? If it does, is it possible to tell it to use a different compiler?


Regarding NDK r8d it can be modified in 2 ways (see Andriod ndk):

  • For ndk-build, export the NDK_TOOLCHAIN_VERSION=4.7 variable or add it to Application.mk.
  • For standalone builds, add the --toolchain= option to make-standalone-toolchain.sh --toolchain=arm-linux-androideabi-4.7

Default compiler is set in ndk/build/core/setup-toolchain.mk (see NDK_TOOLCHAIN and NDK_TOOLCHAIN_VERSION)


The NDK itself invokes a customized cross-compiler built on the arm-eabi-gcc compiler. There are examples out there of people creating custom toolchains using bog-standard GCC implementations with support for ARM instruction sets but that's way out of my league. Most of the stuff I've read in the past always discussed using the toolchain included with the NDK to compile native code.

Corollary: Most of the people who have complained and have had to make their own toolchain have been people that were upset with the (supposed) sub-par C++ support of the NDK toolchain's compiler. I can't speak to this because some of the articles were older and Android changes so rapidly. It also hasn't been an opinion that seems to pop up all too frequently.


GCC is deprecated in favor of clang as of NDK 11 (March 2016)

Mentioned on the official revision history: https://developer.android.com/ndk/downloads/revision_history.html

How to switch between compilers is asked at:

  • How to switch between gcc and clang in Android NDK Revision 11?
  • Latest C++11 features with Android NDK

And you can check it easily with:

enum CONSTEXPR {N = 256};
char s[N];
#ifdef __clang__
        snprintf(s, N, "%s", "clang" __clang_version__);
#else
# ifdef __GNUC__
        snprintf(s, N, "%s %d.%d.%d", "gcc", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# endif
#endif

then just log s or return it to a TextView.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号