Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pure C++ program compiled for Android

I want to compile this program for Android and see it run on my phone:

#include "Hello World.h"

using namespace codewerks;

//=============================================
// Main Loop
//=============================================
int main(int argc, char* argv[])
{
        Print(std::string("Hello World!"));
}

Where do I start? Can I compile this with GCC? The NDK seems focused on Java. Thank you.

like image 413
User Avatar asked Aug 20 '10 15:08

User


2 Answers

This is now possible with the latest NDK. You will need an emulator or phone running Android 2.3 to try it, but the NativeActivity documentation has a complete example.

Unfortunately it is somewhat more complicated than a simple "hello world" example, and "main" is spelled "android_main". You still need to worry about your application life cycle as you do in Java, and the only real way to draw to the screen is to use OpenGL ES. It seems to be designed for writing games for Android.

like image 156
richq Avatar answered Sep 20 '22 17:09

richq


Build as executable. (BUILD_EXECUTABLE)
Copy the executable to sdcard. (adb push)
Go to android shell. (adb shell)
Change the permission of the executable. (chmod 777)
Run the executable. (./out)
You will see the printed result on the console. (happy?)

like image 38
StarDust Avatar answered Sep 23 '22 17:09

StarDust