简体   繁体   English

Android NDK 使用哪个编译器?

[英]Which compiler does Android NDK use?

I'm writing ARM NEON-based code for an Android application and I was struggling with certain compiler flags not being recognized.我正在为 Android 应用程序编写基于 ARM NEON 的代码,但我正在努力解决某些编译器标志无法识别的问题。 I later realized that support for those flags was only added quite recently and that my GCC version is older.后来我意识到对这些标志的支持是最近才添加的,而且我的 GCC 版本较旧。 I'm doing the whole thing on Windows and am limited by what versions Cygwin has to offer.我正在 Windows 上做所有事情,并且受到 Cygwin 提供的版本的限制。 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? 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?如果是这样,是否可以告诉它使用不同的编译器?

Regarding NDK r8d it can be modified in 2 ways (see Andriod ndk ):关于 NDK r8d,它可以通过 2 种方式进行修改(参见Andriod ndk ):

  • For ndk-build, export the NDK_TOOLCHAIN_VERSION=4.7 variable or add it to Application.mk.对于 ndk-build,导出 NDK_TOOLCHAIN_VERSION=4.7 变量或将其添加到 Application.mk。
  • For standalone builds, add the --toolchain= option to make-standalone-toolchain.sh --toolchain=arm-linux-androideabi-4.7对于独立构建,将 --toolchain= 选项添加到 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)默认编译器在 ndk/build/core/setup-toolchain.mk 中设置(参见 NDK_TOOLCHAIN 和 NDK_TOOLCHAIN_VERSION)

The NDK itself invokes a customized cross-compiler built on the arm-eabi-gcc compiler. NDK 本身调用基于arm-eabi-gcc编译器的定制交叉编译器。 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.有一些例子表明人们使用沼泽标准 GCC 实现创建自定义工具链,并支持 ARM 指令集,但这超出了我的范围。 Most of the stuff I've read in the past always discussed using the toolchain included with the NDK to compile native code.我过去读过的大部分内容都讨论过使用 NDK 中包含的工具链来编译本机代码。

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.推论:大多数抱怨并不得不制作自己的工具链的人都是对 NDK 工具链编译器的(假定的)低于标准的 C++ 支持感到不满的人。 I can't speak to this because some of the articles were older and Android changes so rapidly.我不能这么说,因为有些文章比较旧,而且 Android 变化如此之快。 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)自 NDK 11(2016 年 3 月)起,GCC 已弃用,取而代之的是 clang

Mentioned on the official revision history: https://developer.android.com/ndk/downloads/revision_history.html官方修改历史上提到: 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 .然后只需记录s将其返回到TextView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM