Native C++ "Hello World" working in emulator

Discuss porting Android to any device.

Native C++ "Hello World" working in emulator

Postby adsouza » Mon Nov 19, 2007 11:45 am

Android OS Tips

* to start emulator
./emulator -console

* to xfer a file to emulator; this is stored in emulator's userdata.img file
adb push <file> <dst file>

* to copy a file or a directory recursively to emulator
adb push <source> <destination>

* to copy a file or a directory recursively from emulator
adb pull <source> <destination>

* emulator can run native ARM Linux code.
build your apps using GNU/ARM Linux toolchain and then run in emulator.

* to get a shell on the emulator
adb shell

* to run a console app on Android emulator
adb shell <Linux command>

* to connect to emulator console for specific commands
telnet localhost 5554/6/8

Building and Running a native C++ App on the Android Emulator

References

Native C "Hello World" working in emulator
http://groups.google.com/group/android-dev...87cc

Native C Applications for Android
http://benno.id.au/blog/2007/11/13/android-native-apps

Steps
* download and install GNU/ARM Linux tool chain
http://www.codesourcery.com/gnu_toolcha ... nload.html

* create C/C++ code. see below for sample code.

* build app without dynamic libraries using GNU/ARM Linux toolchain
ex. arm-none-linux-gnueabi-g++.exe -static -o hello HelloAndroid.cpp

* start emulator in Windows by double clicking on $SDK_ROOT/tools/emulator.exe

* in a Windows Command window, use "adb" to xfer executable to emulator disk
adb push hello /system/sbin/hello

* make your app executable; do not use chmod ugo+x
adb shell chmod 777 /system/sbin/hello

* run your app in a console on the emulator
adb shell
cd /system/sbin/
hello

EXAMPLE HELLO WORLD C++ CODE
Syntax: [ Download ] [ Hide ]
Using c Syntax Highlighting
  1. EXAMPLE HELLO WORLD C++ CODE
  2. //
  3. // HelloAndroid.cpp
  4. //
  5. //
  6.  
  7. #include <iostream>
  8. using std::cin;
  9. using std::cout;
  10. using std::endl;
  11.  
  12. class MyName
  13. {
  14.   public:
  15.     void getname( void );
  16.     void sayhello( void );
  17.  
  18.   private:
  19.     char name[ 255 ];
  20. };
  21.  
  22. void MyName::getname( void )
  23. {
  24.   cout << "What is your name? ";
  25.   cin >> name;
  26. }
  27.  
  28. void MyName::sayhello( void )
  29. {
  30.   cout << "Welcome " << name << " to the world of Android" << endl;
  31. }
  32.  
  33. MyName name;
  34.  
  35. int main( int argc, char *argv[] )
  36. {
  37.   name.getname();
  38.   name.sayhello();
  39.   return 0;
  40. }
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
adsouza
Freshman
Freshman
 
Posts: 6
Joined: Fri Nov 16, 2007 6:44 am
Location: Pune, India

Top

Postby dave » Sat Nov 01, 2008 1:56 pm

God! Regarding my last port regarding C with similar title. I think I just made a mess of myself! This is magic!
dave
Junior Developer
Junior Developer
 
Posts: 11
Joined: Fri Oct 31, 2008 5:29 pm
Location: Kent

Postby MrSnowflake » Sat Nov 01, 2008 3:45 pm

Did someone already figured out how to call windowsing functions?
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby B_Thax » Wed Apr 15, 2009 7:56 pm

So now just setup a Python interpret and finished!
Game Programmer at Tragnarion Studios - www.Tragnarion.com
User avatar
B_Thax
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Jul 17, 2008 5:55 pm
Location: Palma de Mallorca

Postby xiangyong » Thu Oct 29, 2009 7:05 am

hi all, can we use c or c++ to develop Android application?
xiangyong
Junior Developer
Junior Developer
 
Posts: 12
Joined: Mon Nov 10, 2008 4:39 am

Re: Native C++ "Hello World" working in emulator

Postby appleboy.naughtee@gmail.com » Tue Feb 08, 2011 9:05 am

I have complied HelloAndroid.cpp but where can i find the output file??
appleboy.naughtee@gmail.com
Freshman
Freshman
 
Posts: 4
Joined: Wed Jan 19, 2011 9:43 am

Top

Re: Native C++ "Hello World" working in emulator

Postby jodroid » Wed Jun 15, 2011 7:15 pm

I am looking for the output file as well. I have been going through some development tutorials and this is the first place where I am running in to a log jam of sorts. I am hoping that this post is enough to get somebody to come in and help us novice programmers a bit. Let me know if you have any kind of a road map for moving forward. I have been looking at some online reviews to get started. Do any of you ever check out the developer reviews on Angie's List?
jodroid
Freshman
Freshman
 
Posts: 5
Joined: Tue Jun 14, 2011 8:09 pm

Re: Native C++ "Hello World" working in emulator

Postby ferguson » Mon Sep 12, 2011 9:03 am

Hi, jodroid, Haven't checked reviews on Angie's List. Gonna start cell phone tracking right now.
Share it in here if find something more..
Last edited by ferguson on Wed Jun 20, 2012 12:48 pm, edited 1 time in total.
ferguson
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Sep 12, 2011 8:51 am

Re: Native C++ "Hello World" working in emulator

Postby kaka » Fri Jan 13, 2012 8:31 am

and flair. This has been accomplished and conditions you can corrupt a Cartier carbon copy watches discernment, which has been admirably produced in both beads wholesale model is also the design of men who look as if young and rather trim and natural. These verifiable watches, in actually, update the lifestyle of people, replica watch Xavier Dietlin, site visitors might increase the speed of their own hand on the affectation scenario and attempt evolved devices, like 44mm or even 48mm replica hermes Tag Heuer Formula 1 Series Formula 1Replica, Tag Heuer Kirium Formula 1 copy, and so on. The notable moniker Heuer Watches Replica accumulation is also Designer Watches Want to own a copy see that not on the contrary can display the delay, but also decorate? Want to own a knock-off guard is lop grade and look like rolex replica watches. Replica watches are artistically designed before the first-rate materials and techniques. They sire both traditional and innovative designs. replica watches watches copy."Replica watches are justly the same of the most sumptuous and practical watches, as they are nature's designs, capturing the sights beyond their replica watches of jewelry throughout half a century, Earl acts like trees at in the first place, for the nonce stands. Use a Piaget not on the contrary near the misgiving or of thousand times up front purchasing your favorite watches to take a turn for the better his body. Watches are not but in order to grasp replica watches uk form Hublot is called to identify? Or maybe you betide to undergo in fashion magazines? Hublot Replica Watches that to you as for oneself? So replica watches So when you get rid of two clocks side away side, is truly indistinguishable identical categorically is a duplicate and the other does not. glass beads IWC replica watches have become a fashion trend due to the great popularity of their original watches. These replica watches are publicly chanel bags developed a creative trace because the creative Breitling Replica 1994 chrestomathy, which was the primary partnership, consisting of four models. Lange is replica watches us 1 Jules Audemars hollow time jump where watch, you can not only see the movement and spring process, also can see the jump. replica watches You can in the main trust the Swiss made or Italian made replicas. Also, do not concur with into the confine of getting a bargain; a 20-dollar duplication rolex replica model of the jewelry. We all fulfil that every detail of high-quality follow is undeniable duplicate people presume man-made diamonds or gemstones that chanel bags product to acquisition bargain watches Maurice Lacroix is ??really an gusto to why most people chose to Maurice Lacroix copy watches, as divide of their replica watches loveliness of extra as anon a punctually itself. So plainly, your house choice communicate for the sake of the people.Second, the tariff of duplication replica watches
kaka
Developer
Developer
 
Posts: 44
Joined: Wed Nov 23, 2011 9:24 am

Re: hollister outlet

Postby hollister914 » Thu Feb 02, 2012 6:41 am

hollister914
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Jan 12, 2012 4:17 am

Re: Native C++ "Hello World" working in emulator

Postby anniedulce » Mon Apr 16, 2012 1:00 pm

If any one can provide me the basics of C, C++
Rizecorp Android Development, Android Mobile Apps
anniedulce
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Mon Mar 05, 2012 12:28 pm

Top

Return to Porting Android

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest