如何在Android系统(如Windows上的MinGW)上编译和运行C/C++程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3641403/
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 11:06:44  来源:igfitidea点击:

How to compile and run a C/C++ program on the Android system (like MinGW on the Windows)?

androidcompiler-constructionandroid-emulator

提问by huaigu

I want to compile and run the C/C++ program on the Android phone program (like G1).

我想在Android手机程序(如G1)上编译并运行C/C++程序。

For example, I write a "Hello World.c" program, then compile and run it on my Android phone system.

例如,我编写了一个“Hello World.c”程序,然后在我的 Android 手机系统上编译并运行它。

I have never used MinGW to run my code on my Windows system, so I also want to do it on the Android phone system.

我从来没有用MinGW在我的Windows系统上运行过我的代码,所以我也想在Android手机系统上运行。

回答by Open ids Are dumb

At the time of the other answers, it may have been true that there were no development options. However, that area is changing quickly. There are several projects now where you can develop in some languages. Not all utilities support all ansi standards of the languages yet. As an example the project C4droid seems to aim to give full ansi C/C++.

在其他答案时,可能确实没有开发选项。然而,该领域正在迅速变化。现在有几个项目可以使用某些语言进行开发。并非所有实用程序都支持这些语言的所有 ansi 标准。例如,项目 C4droid 似乎旨在提供完整的 ansi C/C++。

https://play.google.com/store/apps/details?id=com.n0n3m4.droidc&hl=en

https://play.google.com/store/apps/details?id=com.n0n3m4.droidc&hl=en

回答by 4ntoine

I'd recommend CppDroid- new free C/C++ IDE and compiler on Android. It has a lot of included C/C++ examples and tutorials. YouTube: https://www.youtube.com/watch?v=4T5qNP6xJ6Y#t=14Blog: http://cppdroid.blogspot.com, Google Play: https://play.google.com/store/apps/details?id=name.antonsmirnov.android.cppdroid

我推荐CppDroid- Android 上新的免费 C/C++ IDE 和编译器。它包含大量的 C/C++ 示例和教程。YouTube:https: //www.youtube.com/watch?v=4T5qNP6xJ6Y# t =14博客:http: //cppdroid.blogspot.com,GooglePlay:https: //play.google.com/store/apps/详细信息?id=name.antonsmirnov.android.cppdroid

回答by CommonsWare

Android does not have a C/C++ compiler on its devices, sorry. There are ways to create C/C++ libraries for use with Android (see the NDK), but those are compiled on a host machine, not on the device itself.

抱歉,Android 设备上没有 C/C++ 编译器。有多种方法可以创建用于 Android 的 C/C++ 库(请参阅 NDK),但这些是在主机上编译的,而不是在设备本身上编译的。

回答by Mark Ingram

The only way of using C/C++ in Android is to use the Android NDK.

在 Android 中使用 C/C++ 的唯一方法是使用Android NDK

回答by Behrooz


today i just tried a new thing
it is super-hacky but works great after you set it up.
first root your phone(use something easy like z4root).
and follow the instructions here:
http://www.gphone.org.hk/cgi-bin/ch/threaded_show.cgi?tid=69&pid=222&h=1


今天我刚刚尝试了一个新东西,
它超级hacky,但在你设置后效果很好。
首先root你的手机(使用像z4root这样简单的东西)。
并按照此处的说明进行操作:http: //www.gphone.org.hk/cgi-bin/ch/threaded_show.cgi?tid=69&pid=
222&h=1

If it is hard for you to use adb, then your just like me.use QuickSSHd.
DO NET SET THE SAME PASSWORD FOR QuickSSHd and OpenSSH.it won't make any changes in the process, but helps you not to get confused.
After you done everything,
be sure that the last few statements have worked correctly./this one may hurt

如果你很难使用 adb,那么你就像我一样使用 QuickSSHd。
请务必为 QuickSSHd 和 OpenSSH 设置相同的密码。它不会在此过程中进行任何更改,但可以帮助您避免混淆。
完成所有操作后,请
确保最后几条语句正确运行。/这一条可能会造成伤害

After you make sure than OpenSSH is installed Correctly.
Close QuickSSHd and ssh into your Debian.

确保正确安装 OpenSSH之后。
关闭 QuickSSHd 并通过 ssh 进入您的 Debian。

then you can
apt-get install g++

然后你可以
apt-get install g++

Update to squeeze after you make sure it works.

确保它有效后更新以挤压。

And have fun.

玩得开心。

Hint: never close the shell in the process == use usb network instead of wifi if possible

提示:在此过程中切勿关闭外壳 == 如果可能,请使用 USB 网络而不是 wifi

Any questions, I'm ready.

有任何问题,我准备好了。