开发者

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
//=====================================开发者_Python百科========
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.


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.


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?)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜