如何为Android编译GCC?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11852187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:00:56  来源:igfitidea点击:

How to compile GCC for android?

androidgcccompiler-constructionmakefilecross-compiling

提问by glen3b

Is there any way to compile GCC for android? Basically, have the GCC compiler accessible in an android terminal emulator and able to compile a binary that will run on android from a C or C++ source file.

有没有办法为android编译GCC?基本上,让 GCC 编译器可以在 android 终端模拟器中访问,并且能够从 C 或 C++ 源文件编译将在 android 上运行的二进制文件。

My intention is to use this and eventually install make.

我的目的是使用它并最终安装 make。

采纳答案by Michael Hampton

The Android NDKalready includes the complete GNU toolchain which runs on your computer. You should be able to use it to compile native versions of whatever program you want.

Android的NDK已经包括在计算机上运行完整的GNU工具链。您应该能够使用它来编译您想要的任何程序的本机版本。

In the NDK, see docs/STANDALONE-TOOLCHAIN.htmlfor setting up the cross-compiler. You probably want to follow the steps for "Invoking the compiler (the easy way)" to set up a copy of the toolchain which you should be able to use with configurescripts commonly included with GNU applications (like gcc).

在 NDK 中,请参阅docs/STANDALONE-TOOLCHAIN.html设置交叉编译器。您可能希望按照“调用编译器(简单方法)”的步骤来设置工具链的副本,您应该能够将其configure与 GNU 应用程序(如 gcc)中通常包含的脚本一起使用。

This really is a non-trivial task and I recommend you read the docs very carefully. It also contains various values for CFLAGS, LDFLAGS etc. that you will need to customize and use when configuring and compiling your programs.

这确实是一项非常重要的任务,我建议您非常仔细地阅读文档。它还包含 CFLAGS、LDFLAGS 等的各种值,您在配置和编译程序时需要自定义和使用这些值。

As for compiling gcc, make, etc., themselves, it's probably not necessary or desirable to do so. gcc, for instance, is going to be huge and you may not have enough storage on the phone to install it. If your ultimate intention is to compile some program to run natively on the Android device, then I would recommend you just use the NDK and point the app's configurescript at it.

至于自己编译 gcc、make 等,可能没有必要或不需要这样做。例如,gcc 会很大,你可能没有足够的手机存储空间来安装它。如果您的最终目的是编译一些程序以在 Android 设备上本地运行,那么我建议您只使用 NDK 并将应用程序的configure脚本指向它。