Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Mobile
User Name
Linux - Mobile This forum is for the discussion of all topics relating to Mobile Linux. This includes Android, Tizen, Firefox OS, Sailfish OS, Maemo, MeeGo, Ubuntu Mobile, WebOS, Open Mobile Alliance and other similar projects and products.
A reminder that LQ now has a dedicated Android sister site:


  Search this Thread
Old 09-25-2010, 10:05 PM   #1
Registered: Sep 2010
Posts: 58

Rep: Reputation: 0
Smile 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?


P.S. My phone is milestone x702 and my terminal emulator is "Better Terminal Emulator Pro"
Old 09-25-2010, 11:46 PM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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:

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:

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!
Old 09-28-2010, 07:11 AM   #3
Registered: Sep 2010
Posts: 58

Original Poster
Rep: Reputation: 0
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?
Old 09-29-2010, 08:56 AM   #4
Senior Member
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
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.

Last edited by Agrouf; 09-29-2010 at 08:58 AM.
Old 09-30-2010, 12:35 AM   #5
Senior Member
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 56
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to run a .cpp file in terminal? the_rastaman Gentoo 5 04-11-2010 10:40 PM
How to compile a C++ file (.cpp) with allegro? RHLinuxGUY Programming 5 11-29-2005 02:06 AM
how to run a compile file in shell? v3sS0n Linux - Newbie 2 09-25-2004 05:47 AM
compile programs in c and cpp Manjula.S Linux - Software 2 10-15-2003 01:06 AM
For some reason I can't compile a .cpp file with kdevelop, the button is greyed out. Manyguns Programming 1 07-16-2001 10:27 AM > Forums > Linux Forums > Linux - Mobile

All times are GMT -5. The time now is 06:33 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration