Getting started with GP2X

Home / Support / Tutorials / Getting Started / Getting started with GP2X

Required tools and SDKs

When targetting the GP2X platform, you need the devkitPro GP2X SDK. The SDK contains all headers and libraries and includes gcc as well, an open source c++ compiler. Run the executable to install the contents of the SDK to c:\devkitGP2X. To build for this platform, use gcc through the commandline or use the EDGELIB Builder tool (formerly Edge IDE). We recommend using the EDGELIB Builder tool for building GP2X applications. A tutorial on how to set up the EDGELIB Builder tool is available.

Creating a .cpp source code file

Create a new folder: C:\projects\helloworld which will contain all project files. Also create a new folder: C:\projects\helloworld\code to contain the source code. Create a new helloworld.cpp file and edit it with a text editor. Paste the following source code sample and save the source file:

helloworld.cpp (72 lines)
  1. /////////////////////////////////////////////////////////////////////
  2. // Code/helloworld.cpp
  3. // One of the EDGELIB tutorial samples for GP2X
  4. //
  5. // Copyright (c) 2006-2017 Elements Interactive Mobile B.V.
  6. //
  7. //
  8. // Show "hello world" on the screen and exit by hitting a key
  9. /////////////////////////////////////////////////////////////////////
  11. /////////////////////////////////////////////////////////////////////
  12. // Include and link the library                                    //
  13. /////////////////////////////////////////////////////////////////////
  15. //Include EDGELIB
  16. #include "edgemain.h"
  18. /////////////////////////////////////////////////////////////////////
  19. // Class definition                                                //
  20. /////////////////////////////////////////////////////////////////////
  22. //The main class
  23. class ClassMain : public ClassEdge
  24. {
  25.     public:
  26.         ClassMain(void);
  27.         ~ClassMain(void);
  28.         ERESULT OnNextFrame(ClassEDisplay *display, unsigned long timedelta);
  29.         void OnButtonDown(unsigned long bnr, EBUTTONLIST *blist);
  30.         void OnStylusDown(POINT pnt);
  31. };
  34. /////////////////////////////////////////////////////////////////////
  35. // ClassMain: public                                               //
  36. /////////////////////////////////////////////////////////////////////
  38. //ClassMain: constructor
  39. ClassMain::ClassMain(void)
  40. {
  41. }
  43. //ClassMain: destructor
  44. ClassMain::~ClassMain(void)
  45. {
  46. }
  48. //Callback: Called every frame
  49. ERESULT ClassMain::OnNextFrame(ClassEDisplay *display, unsigned long timedelta)
  50. {
  51.     display->buffer.DrawFont(0, 0, &display->fontinternal, "Hello World!");
  52.     return(E_OK);
  53. }
  55. //Callback: Called when the user pressed a key or button
  56. void ClassMain::OnButtonDown(unsigned long bnr, EBUTTONLIST *blist)
  57. {
  58.     Quit();
  59. }
  61. //Callback: Called when the user points the stylus down or clicks the left mouse button
  62. void ClassMain::OnStylusDown(POINT pnt)
  63. {
  64.     Quit();
  65. }
  68. /////////////////////////////////////////////////////////////////////
  69. // The program entry point                                         //
  70. /////////////////////////////////////////////////////////////////////
  72. ClassEdge *EdgeMain(EDGESTARTUP *data){ return(new ClassMain); }

Set up a GP2X EDGELIB Builder project

Open the EDGELIB Builder and select project -> new. Choose a location to save your project. Create a new folder and save it in c:\projects\helloworld\workspace_gp2x. Click once on "untitled" in the project tree to rename it to Hello World, the name of the project. Then add helloworld.cpp to the source files folder in the project tree. Right click on this folder and select "add files to folder". Browse to helloworld.cpp and open it to add it to the project tree. Save the project file, choose "GP2X" as the target platform and click build -> rebuild all. The folder c:\projects\helloworld\workspace_gp2x\release\gp2x contains a .gpe file. This file can be copied to a GP2X device and can be executed from the menu.

Using the commandline

The commandline tools can be found in the bin folder of the GP2X SDK. Open a command window in the same folder as the .cpp source file and execute the following commands to compile an object file:
set path=%path%;c:\devkitGP2X\bin
arm-linux-g++ -O3 -I c:\projects\edge\include -D__LINUX__ -D__GP2X__ -c helloworld.cpp -o helloworld.obj

This will link the object file and libraries into the executable file and strips the executable to decrease its filesize:
arm-linux-g++ helloworld.obj --whole-archive -static -ledge -ledgerender -lz --no-whole-archive -L c:\projects\edge\lib\gp2x -o helloworld.gpe


At the moment, a GP2X application will hang the device when a floating point datatype is defined, or a floating point calculation is executed. Be careful when using functionality that's not part of the EDGELIB SDK. To add an icon to a GP2X application, create a 32x32 pixel PNG file with the same name as the .gpe executable. It should also be located in the same folder.

Download tutorial project

Here is a sample that can be downloaded which contains the result of this tutorial.

Getting started tutorials

Latest forum posts