Which compiler does Android NDK use?

28,436

Solution 1

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.

Solution 2

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)

Solution 3

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:

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.

Share:
28,436

Related videos on Youtube

Phonon
Author by

Phonon

Updated on July 12, 2022

Comments

  • Phonon
    Phonon almost 2 years

    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 the GCC and my upgrade will not at all affect it? If it does, is it possible to tell it to use a different compiler?

  • rubenvb
    rubenvb almost 13 years
    It probably is just a bog-standard GCC, but built with the correct options set. In theory, gcc -v output should show a line Configured with: ... showing how GCC was built. Replace gcc with the matching some-prefix-gcc in some bin directory of the NDK of course.
  • Doug Stephen
    Doug Stephen almost 13 years
    @rubenvb Most likely. But since I can't speak for Google I can't say that with any level of confidence.
  • rubenvb
    rubenvb almost 13 years
    You can download the NDK, and there will be a build/tools/toolchain-patches folder, with mostly "trivial" GCC build patches to work with Android's system library. So yeah, plain GCC it (almost) is.
  • trampster
    trampster about 4 years
    android ndk changed to use clang, so this answer is no longer correct