LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Mobile (https://www.linuxquestions.org/questions/linux-mobile-81/)
-   -   How can I compile a .c or .cpp file and let it run on my phone? (https://www.linuxquestions.org/questions/linux-mobile-81/how-can-i-compile-a-c-or-cpp-file-and-let-it-run-on-my-phone-834510/)

lesca 09-25-2010 10:05 PM

How can I compile a .c or .cpp file and let it run on my phone?
 
Hello everyone

I want to compile some commands to run on my android phone with gcc or g++.

I searched the gcc manual but found there are so many options related to ARM.

So which options should I use when compiling?

Could you give me some suggestions?

Thx!!

P.S. My phone is milestone x702 and my terminal emulator is "Better Terminal Emulator Pro"

paulsm4 09-25-2010 11:46 PM

Hi -

Just because you compile some code for an ARM CPU, doesn't necessarily mean that code will execute as-is on Android. Any more than it'll execute as-is on Windows CE (which also supports ARM).

Yes, you can compile C++ code to run under Android. To do this, you need to download the Android NDK:

http://developer.android.com/sdk/ndk/index.html

Frankly, though, this is several orders of magnitude more difficult than simply using the (Java) SDK. I would strongly encourage to you try using Java first, and C++ only as a last resort, if you absolutely have to. Here's where you can find the current SDK:

http://developer.android.com/

And here's a book I've found helpful to familiarize myself with Android:

Android Application Development, Lauren Darcey and Shane Conder
ISBN 0-321-67355-2

'Hope that helps!

lesca 09-28-2010 07:11 AM

Hello paulsm4

Thanks for your advice, and I have the plan to develop some .apk files on Android.

But now I am learning Linux programming, and I want to compile some binary files which can directly run on Android.

I saw many options about ARM in the gcc manual pages. And what I what to know is just an example of using them.

So could you please offer an simple example for me?

Agrouf 09-29-2010 08:56 AM

Actually Android is not really linux. Android is a java OS which happens to run linux as a kernel but it is not exposed. You can't compile a binary for it that is executed by the linux kernel directly.
If you want a true mobile GNU/linux system, you should give Maemo a try.

Kenny_Strawn 09-30-2010 12:35 AM

And even Chrome OS is more like Linux than Android; just look at Wikipedia's Google Chrome OS article for details. It includes a package manager, GNU coreutils, GCC, and even X, unlike Android.


All times are GMT -5. The time now is 12:29 AM.